Department Top Three Salaries(Window함수)
문제
코드
Window함수 사용
MS SQL Server/Oracle
SELECT T.DEPARTMENT
, T.EMPLOYEE
, T.SALARY
FROM (
SELECT DEPARTMENT.NAME AS DEPARTMENT
, EMPLOYEE.NAME AS EMPLOYEE
, EMPLOYEE.SALARY
, DENSE_RANK() OVER (PARTITION BY DEPARTMENTID ORDER BY SALARY DESC) AS DR
FROM EMPLOYEE
INNER JOIN DEPARTMENT ON EMPLOYEE.DEPARTMENTID = DEPARTMENT.ID
) T
WHERE T.DR <= 3