Contents

Department Top Three Salaries(Window함수)

   Apr 2, 2023     0 min read

Department Top Three Salaries

문제

185-1.jpg
185-2.jpg
185-3.jpg

코드

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

수행결과

185result.jpg