Lc185-部门工资前三高的所有员工

SELECT
d.Name AS 'Department', e1.Name AS 'Employee', e1.Salary
FROM
Employee e1
JOIN
Department d ON e1.DepartmentId = d.Id
WHERE
--子查询 逆向思维
3 > (SELECT
COUNT(DISTINCT e2.Salary)
FROM
Employee e2
WHERE
e2.Salary > e1.Salary
AND e1.DepartmentId = e2.DepartmentId
)
posted @ 2020-01-12 15:22  小傻孩丶儿  阅读(107)  评论(0编辑  收藏  举报