image.png
解题思路
哇,这sql也不简单
首先如何找部门前三高工资:
select salary
from e1
where (select from e2 where e2>e1 )<3
前三means:大于这个数的工资必须小于3,最大是2
解决这个问题就ok
代码
# Write your MySQL query statement below
select d1.name Department,e1.name Employee,e1.Salary Salary
from Employee e1 inner join Department d1 on e1.DepartmentId=d1.Id
where (select count(distinct e2.Salary) from Employee e2
where e2.Salary>e1.Salary and e2.DepartmentId=e1.DepartmentId
)<3
网友评论