[LeetCode/SQL] 176. Second Highest Salary

Sooyeon·2023년 12월 4일
0

문제풀이 

목록 보기
70/95
post-thumbnail

[LeetCode/SQL]


📌 176. Second Highest Salary

문제

풀이

직원별로 월급이 두번째로 높은 직원의 월급을 출력하라 

방법 I

SELECT(SELECT DISTINCT salary 
       FROM Employee
       ORDER BY salary DESC
       LIMIT 1,1)
AS SecondHighestSalary

방법 II

SELECT(SELECT DISTINCT salary 
       FROM Employee
       ORDER BY salary DESC
       LIMIT 1 OFFSET 1)
AS SecondHighestSalary

방법 III

SELECT MAX(Salary) AS SecondHighestSalary 
FROM Employee
WHERE Salary NOT IN (
    SELECT MAX(Salary) FROM Employee
)

0개의 댓글