알고리즘

[LeetCode 릿코드] 176. Second Highest Salary

yoozung 2022. 11. 8. 00:23

문제

Employee 테이블에서 두 번째로 높은 급여를 보고하는 SQL 쿼리를 작성하십시오.
두 번째로 높은 급여가 없는 경우 쿼리는 null을 보고해야 합니다.

 

select ifnull(
				(select distinct salary 
                   from Employee 
                  order by salary desc 
                  limit 1,1)
               ,null) as SecondHighestSalary
;

limit 함수를 이용해서 2번째 값 출력하고
ifnull 함수를 이용해서 null 처리