데이터 분석/SQL 연습문제
185. Department Top Three Salaries (LeetCode)
중급닌자 연습생
2022. 9. 26. 20:03
A high earner in a department is an employee who has a salary in the top three unique salaries for that department. Write an SQL query to find the employees who are high earners in each of the departments.
풀이
제출한 답
with sub as(
select
d.name department,
e.name employee,
e.salary salary,
dense_rank() over (partition by d.id order by salary desc) as rn
from employee as e join department as d on e.departmentId = d.id)
select department, employee, salary
from sub
where rn <= 3
-> dense_rank로 중복 포함 순위 구하기