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로 중복 포함 순위 구하기
'데이터 분석 > SQL 연습문제' 카테고리의 다른 글
Contest Leaderboard (HackerRank) (0) | 2022.10.04 |
---|---|
Weather Observation Station 17 (HackerRank) (0) | 2022.09.29 |
The Report (HackerRank) (0) | 2022.09.20 |
Challenges (HackerRank) (0) | 2022.09.19 |
184. Department Highest Salary (LeetCode) (0) | 2022.09.18 |
댓글