본문 바로가기
취준/코팅 테스트

[LeetCode] - 176.Second Higest Salary

by 소복소복뚜벅뚜벅 2024. 3. 13.

문제 

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

Write a solution to find the second highest salary from the Employee table. If there is no second highest salary, return null (return None in Pandas).

The result format is in the following example.

 

 

풀이 

SELECT MAX(salary) AS SecondHighestSalary 
FROM Employee
WHERE salary <> (
    SELECT MAX(salary)
    FROM Employee 
    )

 

 

오답 이유

1. 서브 쿼리가 바로 떠오르지 않았음. 

2. 가장 큰 값을 제외한 나머지 숫자들에서 최대값을 생각하긴 했지만 어떻게 구현해야 할지 몰랐음.