알고리즘/코딩테스트

[SQL] leetcode Second Highest Salary

호두밥 2022. 3. 22. 22:50

 

https://leetcode.com/problems/second-highest-salary/

 

Second Highest Salary - 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

 

 

두번째로 연봉이 높은 직원을 출력하는 문제입니다.

풀이 : rank over 윈도우 함수 사용

 

[Oracle 풀이]

select sum(salary)  as "SecondHighestSalary" from (
select salary, rank() over (order by salary desc) as rank  from employee) where rank = 2;