题目描述:
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 | +---------------------+
中文理解:求出Employee
表中第二高的工资信息。
解题思路:首先子查询求出最大的工资,在外部查询使得查询结果不包含最大的工资数即可。
代码(sql):
select max(salary) as SecondHighestSalary
from Employee
where salary not in (select max(salary) from Employee)