[문제]
department top three salaries 문제 바로 가기
Department Top Three Salaries - LeetCode
Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.
leetcode.com
[풀이]
- 윈도우함수 DENSE_RANK() 이용
* 리트코드 MySQL은 윈도우함수가 안돼서 MSSQL로 풀이
SELECT Department
,Employee
,Salary
FROM (
SELECT de.name AS Department
, em.name AS Employee
, em.salary AS Salary
, DENSE_RANK() OVER (PARTITION BY departmentID ORDER BY salary DESC) drank
FROM employee em
INNER JOIN department de ON de.id = em.departmentID) rank
WHERE rank.drank <= 3
'SQL > MySQL 문제풀이' 카테고리의 다른 글
[HackerRank] weather observation station 8 - 정규표현식 풀이 (0) | 2022.06.27 |
---|---|
[LeetCode] Rank Scores (윈도우함수 풀이) (0) | 2022.06.23 |
[LeetCode] Consecutive Numbers 풀이 (0) | 2022.06.20 |
[LeetCode] department-highest-salary 풀이 (0) | 2022.06.14 |
[SQL DELETE문제][LeetCode] Delete Duplicate Emails (0) | 2022.06.13 |