Skip to content

Latest commit

 

History

History
50 lines (36 loc) · 963 Bytes

0176._Second_Highest_Salary.md

File metadata and controls

50 lines (36 loc) · 963 Bytes

176. Second Highest Salary

难度: Easy

刷题内容

原题连接

内容描述

Write a SQL query to get the second highest salary from the Employee table.

+----+--------+
| Id | Salary |
+----+--------+
| 1  | 100    |
| 2  | 200    |
| 3  | 300    |
+----+--------+
For example, given the above Employee table, the query should return 200 as the second highest salary. If there is no second highest salary, then the query should return null.

+---------------------+
| SecondHighestSalary |
+---------------------+
| 200                 |
+---------------------+

解题方案

思路 1

select Salary SecondHighestSalary from Employee
union
select null
order by SecondHighestSalary desc limit 1, 1

思路 2

select (
  select distinct Salary from Employee order by Salary Desc limit 1, 1
)as SecondHighestSalary