第二高的薪水-leetcode 1. 地址 2. 解法

第二高的薪水


这是一道使用 sql 语句编程的题目

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

2. 解法

两种方法:

  1. 对表进行排序之后,使用 limit 取偏移量
select (
    select distinct Salary
    from Employee
    order by Salary DESC
    limit 1,1) 
as SecondHighestSalary; -- 嵌套一层,为了获取跟预期结果中的 null 对应

  1. 嵌套,两次对表进行取最大值
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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。