알고리즘/코딩테스트

[SQL] leetCode Department Top Three Salaries

호두밥 2022. 3. 24. 23:56

https://leetcode.com/problems/department-top-three-salaries/

 

Department Top Three Salaries - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

부서별로 연봉순위 3위까지 출력하는 문제입니다. 단 동일한 연봉인 경우 동일 순위로 판단합니다. (1등이 2명이더라도 다음 순위는 2등으로 판별)

DENSE RANK 함수를 사용하였습니다.

[Oracle 풀이]

 

SELECT  
	D.NAME AS Department
	, E.NAME AS Employee
    , E.SALARY AS Salary 
FROM 
    (SELECT  
        departmentId 
        , NAME 
        , SALARY
        , DENSE_RANK() OVER (PARTITION BY DEPARTMENTID ORDER BY SALARY DESC ) AS RANK 
     FROM EMPLOYEE) E
INNER JOIN department D
     ON E.RANK <= 3
     AND D.ID = E.departmentId

'알고리즘 > 코딩테스트' 카테고리의 다른 글

[leetcode] number of 1 bits  (0) 2022.04.21
[leetcode] three sum  (0) 2022.04.13
[SQL] leetcode Second Highest Salary  (0) 2022.03.22
[SQL] leetcode Trips and Users  (0) 2022.03.21
리트코드 leetCode 743.Network Delay Time  (0) 2021.11.05