728x90
# Write your MySQL query statement below
SELECT MAX(Salary) as SecondHighestSalary
FROM Employee
WHERE Salary NOT IN (SELECT Max(Salary)
FROM Employee);
NOT IN 으로 max salary를 찾으면
이것이 1st highest salary이기 때문에
이 값을 제외한 나머지 중에서 가장 큰 값을
"SecondHighestSalary"로 출력
출처: www.geeksforgeeks.org/query-to-find-2nd-largest-value-in-a-column-in-table/
728x90
'SQL' 카테고리의 다른 글
[LeetCode] Delete Duplicate Emails (delete, self join, and) (0) | 2021.04.09 |
---|---|
[LeetCode] Customes Who Never Order (is null, join) (0) | 2021.04.09 |
[LeetCode] Duplicate Emails (group by, having) (0) | 2021.04.09 |
[LeetCode] Employees Earning More Than Their Managers (Self Join) (0) | 2021.04.08 |
[MySQL] Code Snippets (0) | 2021.04.08 |
댓글