A company's executives are interested in seeing who earns the most money in each of the company's departments. A high earner in a department is an employee who has a salary in the top three unique salaries for that department.
Write a solution to find the employees who are high earners in each of the departments.
Return the result table in any order.
The result format is in the following example.
salary
상위 3위를 뽑아야한다.DENSE_RANK()
를 사용함에 주의하자.SELECT DEPT_NAME AS Department, NAME as Employee, Salary FROM
(SELECT D.NAME AS DEPT_NAME, E.NAME, E.SALARY,
DENSE_RANK() OVER(PARTITION BY D.NAME ORDER BY E.SALARY DESC) AS RK
FROM DEPARTMENT AS D JOIN EMPLOYEE AS E ON D.ID = E.DEPARTMENTID
) AS SUB
WHERE RK <= 3
ORDER BY DEPT_NAME