本文主要是介绍[LeetCode][Database]Department Top Three Salaries,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
题目来源https://leetcode.com/problems/department-top-three-salaries/
这道题和之前的Department Highest Salary差不多,只是从每个部门最高工资换成输出每个部门前三名的工资。
实在做不出来,后来查到一个很不错的想法。
选出所在部门工资超过他的不超过三人的员工,代码如下:
select D.Name, E.Name, E.Salary
from Employee E, Department D
where (select count(distinct(Salary)) from Employee
where DepartmentId = E.DepartmentId and Salary > E.Salary) in (0, 1, 2)
and
E.DepartmentId = D.Id
order by E.DepartmentId, E.Salary DESC;
最后按部门和工资降序排序
终
这篇关于[LeetCode][Database]Department Top Three Salaries的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!