leetcode 2--Second Highest Salary
阿新 • • 發佈:2018-11-29
https://leetcode.com/problems/second-highest-salary/description/
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 |
+———————+
select salary from employee group by salary union all (select null as salary)
order by salary desc limit 1 offset 2;
limit 限制位數
offset從位置開始
union all
UNION 操作符用於合併兩個或多個 SELECT 語句的結果集。