176. (第二高的薪水)Second Highest Salary

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                 |
+---------------------+
解答:

这个相比于“第 n 高的薪水”的就简单多啦~
# Write your MySQL query statement below

select MAX(Salary) as SecondHighestSalary from Employee
where Salary < (
select MAX(Salary) from Employee);

猜你喜欢

转载自blog.csdn.net/qq_38232598/article/details/80616083