已知表
题目
公司的主管们感兴趣的是公司每个部门中谁赚的钱最多。一个部门的 高收入者 是指一个员工的工资在该部门的 不同 工资中 排名前三 。
编写一个SQL查询,找出每个部门中 收入高的员工 。
以 任意顺序 返回结果表。
示例
参考答案
select
base.Department,
base.Employee,
base.Salary
from
(select
b.name as 'Department',
a.name as 'Employee',
a.salary as 'Salary',
dense_rank() over(partition by a.departmentId order by a.salary desc) as 'salary_rank'
from
Employee a
join
Department b
on
a.departmentId = b.id
) as base
where
base.salary_rank <=3
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/department-top-three-salaries