Difficulty 분류 : Hard
My Solution
WITH a as (
SELECT
e.name AS Employee,
e.salary AS Salary,
d.name AS Department
FROM Employee e
JOIN Department d on e.departmentId = d.id
),
b as (
SELECT
*,
/* DENSE_RANK(), RANK() 차이 이해 필요 */
DENSE_RANK() OVER (PARTITION BY Department ORDER BY Salary DESC) AS rk
FROM a
)
SELECT
Department,
Employee,
Salary
FROM b
WHERE rk<=3
'Data Science > Mysql' 카테고리의 다른 글
[LeetCode-HARD] Human Traffic of Stadium 특정 조건에 만족하는 연속된 일자 정보 추출하기 (0) | 2022.05.03 |
---|---|
[LeetCode-HARD] Trips and Users 미확인 사용자의 일별 cancellation rate 구하기 (0) | 2022.05.03 |
[HackerRank] Challenges 문제 코드 (0) | 2021.03.24 |
[STRATASCRATCH] MySQL Coding Problems 러닝포인트 정리 (0) | 2021.03.18 |
[MySQL] Advanced Level List (0) | 2021.03.14 |