각 부서에서 고수입자 top 3 직원을 찾아서 출력하라
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;