[LeetCode/SQL] 185. Department Top Three Salaries

Sooyeon·2024년 1월 16일
0

문제풀이 

목록 보기
94/95
post-thumbnail

[LeetCode/SQL]


📌 185. Department Top Three Salaries

문제

풀이

각 부서에서 고수입자 top 3 직원을 찾아서 출력하라

방법 I

WITH cte AS (
    SELECT 
        d.name AS Department,
        e.name AS Employee,
        salary,
        DENSE_RANK() OVER (PARTITION BY e.departmentId ORDER BY salary DESC) AS salary_rnk
    FROM 
        Employee AS e
    INNER JOIN 
        Department AS d ON e.departmentId = d.id
)

SELECT 
    Department,
    Employee,
    Salary
FROM 
    cte
WHERE 
    salary_rnk <= 3;

0개의 댓글