[SQL문제풀기] Second Highest Salary

silver's avatar
Nov 21, 2025
[SQL문제풀기] Second Highest Salary
Contents
문제MySQL

문제

MySQL

내가 작성한 오답

-- 1 select salary SecondHighestSalary from (select distinct salary from Employee order by salary limit 1 offset 1) a;
notion image
-- 2 -- DENSE_RANK() 때문에 s = 2인 행이 여러 개 생겨서, 서브쿼리가 값 1개가 아니라 여러 행을 리턴 select (select salary from(select dense_rank() over(order by salary desc) s, salary from Employee) a where s = 2) SecondHighestSalary;

내가 작성한 정답

-- 1 select (select distinct salary from Employee order by salary desc limit 1 offset 1) SecondHighestSalary
-- 2 select (select distinct salary from(select dense_rank() over(order by salary desc) s, salary from Employee) a where s = 2) SecondHighestSalary;
-- 3 select max(salary) SecondHighestSalary from Employee where salary < (select max(salary) from Employee);
Share article

silver