难度: 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