Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I have this task:
Write a single query to display the fname and lname of employees whose salary is higher than $5000.
The problem is that there is 2 tables and fname and lname is from the table "employee" and salary is from the table "Job". How do I make this condition work?
I can only write this query, but I don't know how to write the fact that salary is in another table.
SELECT fname, lname FROM employee WHERE fixed_salary > 5000;
Please, help and thank you! :)
SELECT fname, lname FROM employee
INNER JOIN Job ON employee.job_id=job.job_id
WHERE fixed_salary > 5000;
basic SQL joining, read something about e.g. here:
https://dev.mysql.com/doc/refman/8.0/en/join.html
SELECT
e.fname,
e.lname,
j.fixed_salary
FROM employee e
INNER JOIN Job j ON j.id = e.job_id
WHERE j.fixed_salary > 5000;
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 months ago.
Improve this question
so for an assignment I need to Find the manager(s) of the employee(s) who support customer(s) from Canada from the chinook data base
For now I have the following code:
select distinct employee.LastName, employee.EmployeeId, employee.ReportsTo
from customer,
employee
where customer.Country = 'Canada'
and customer.SupportRepId = employee.EmployeeId;
So I get the following results
So I need to get the names of the general manager whose EmployeeId is 2, but I don't know how to put it into one query.
This is an overview of all the employees:
This is an overview of all the customers:
You have to join the the employee table twice:
select distinct employee.LastName, employee.EmployeeId, manager.Lastname
from
customer
join employee as employee on customer.SupportRepId = employee.EmployeeId
join employee as manager on employee.ReportsTo = manager.employeeId
where customer.Country = 'Canada'
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
as part of an inner query I need to select the latest department number (dept_no) where each employee (emp_no) has worked. Note, some employees have worked in multiple departments. The name of this table is dept_emp.
It seems very simple (and probably is), but I haven't been able to figure it out. This is one of the queries I have tried
SELECT dept_no, emp_no, from_date
FROM dept_emp
GROUP BY emp_no
HAVING MAX(from_date);
This doesn't return the right results. for employee "10010" it returns dept_no "d004" and from_date "1996-11-24" while I expected "d006" and "2000-06-26"
Can anyone suggest a working query to me?
Your query is malformed. If MySQL accepts it you are probably running MySQL 5.x. MySQL 8.x does not accept those malformed queries by default anymore.
In order to get the rows you want you can use a subquery. For example:
select
d.dept_no,
d.emp_no,
d.from_date
from dept_emp d
join (
select emp_no, max(from_date) as max_from_date
from dept_emp
group by emp_no
) m on m.emp_no = d.emp_no
and m.max_from_date = d.from_date
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
Write Mysql query with average age counting
Try the following
select
ReportsTo,
count(*) as Members,
avg(age) as Average_Age
from yourTable
where ReportsTo is not null
group by
ReportsTo
This is actually quite easy. This may work for you!
SELECT ReportsTo, COUNT(Members) as Members, AVG(Age) as average
FROM table
GROUP BY ReportsTo
ORDER BY ReportsTo
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
i have a big problem and cant solve that:
i have a table (action) that store two id belong users in each row. one for customers and one for service providers.
name and family of these users are in another table (tablesite) that can be fetch. but i do not know how i can fetch either name and family of customers and also name of family of service_providers .
result should be like this:
example: first line service_provider_id is 33 and customer_id is 34
so i need this:
service_provider: sajad khammar --- customer: akbar ahmadi
SELECT
a.job_id,
CONCAT( s.name, ' ', s.family ) AS service_provider,
CONCAT( c.name, ' ', c.family ) AS customer
FROM action a
INNER JOIN tablesite s
ON a.service_provider = s.id_user
INNER JOIN tablesite c
ON a.customer_id = c.id_user
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
update employees set salary=salary*10/100+salary
where EmployeeID (select EmployeeID from employees where salary<2000)
Try the IN
update employees set salary=salary*10/100+salary
where EmployeeID IN (select EmployeeID from employees where salary<2000)
As suggested by Lamak
update employees set salary=salary*10/100+salary
where salary<2000
Another option.
update employees e1 set salary=salary*10/100+salary
where EXISTS (select NULL
from employees e2
where e2.salary<2000
and e1.EmployeeID = e2.EmployeeID
)
The EXISTS is overkill in your case but may be very usefull.
You should read about it. here's a good start :-) .
In your case you should use only the condition salary<2000 in the WHERE clause.