[코드카타] SQL 61 Second Highest Salary

Data_Student·2024년 12월 10일
0

코드카타

목록 보기
71/82

[코드카타] SQL 61 Second Highest Salary

61. Second Highest Salary
https://leetcode.com/problems/second-highest-salary/submissions/1475023239/

Write a solution to find the second highest distinct salary from 
the Employee table. If there is no second highest salary, return null 
(return None in Pandas).
WITH temp AS ( 
SELECT salary, dense_rank() over(ORDER BY salary DESC) as rnk
FROM Employee 
)
SELECT IF(max(rnk)<2, null, salary) SecondHighestSalary
FROM temp 
WHERE rnk = 2
dense_rank()를 사용한 이유 - 연속된 순위를 구하기 위해

0개의 댓글