Commit dae96967 by yangpengflag

mysql作业

parents
-- 部门工资最高的员工
select d.`Name` as 'Department', e.`Name` as 'Employee',e.Salary
from employee e LEFT JOIN department d on e.DepartmentId = d.Id
where (e.Salary,e.DepartmentId) in (select max(Salary),DepartmentId from Employee group by DepartmentId);
select d.Name as Department,e.Name as Employee,e.Salary
from Department d,Employee e
where e.DepartmentId=d.Id and e.Salary=(Select max(Salary) from Employee where DepartmentId=d.Id);
-- 部门工资前三高的员工
select d.`Name` as 'Department', e.`Name` as 'Employee',e.Salary
from employee e LEFT JOIN department d on e.DepartmentId = d.Id
where 3>(SELECT count(*) from employee e2 where e2.Salary > e.Salary and e.DepartmentId = e2.DepartmentId)
order by e.DepartmentId,e.Salary desc
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment