編寫一個 SQL 查詢,獲取 Employee 表中第二高的薪水(Salary) 。

IdSalary
1100
2200
3300

例如上述 Employee 表,SQL查詢應該返回 200 作為第二高的薪水。如果不存在第二高的薪水,那麼查詢應返回 null。

SecondHighestSalary
200

答案#

1SELECT (
2    SELECT
3        DISTINCT Salary
4    FROM Employee
5    ORDER BY Salary DESC
6    LIMIT 1,1
7) as SecondHighestSalary

原題#

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