第二高的薪水-leetcode
第二高的薪水
这是一道使用 sql 语句编程的题目
1. 地址
https://leetcode-cn.com/problems/second-highest-salary/
2. 解法
两种方法:
- 对表进行排序之后,使用 limit 取偏移量
select (
select distinct Salary
from Employee
order by Salary DESC
limit 1,1)
as SecondHighestSalary; -- 嵌套一层,为了获取跟预期结果中的 null 对应
- 嵌套,两次对表进行取最大值
select max(Salary) SecondHighestSalary
from Employee
where Salary <> (select max(Salary) from Employee );
作者:zuihai
链接:https://leetcode-cn.com/problems/second-highest-salary/solution/xian-qu-diao-di-yi-zai-qiu-zui-gao-tong-shi-jie-ju/
来源:力扣(LeetCode)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
本文来自博客园,作者:吴丹阳-V,转载请注明原文链接:https://www.cnblogs.com/wudanyang/p/13071979.html