第二高的薪水


这是一道使用 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)
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

相关文章:

  • 2021-07-26
  • 2021-09-09
  • 2021-10-24
  • 2021-08-28
  • 2021-06-17
  • 2022-12-23
  • 2021-08-03
  • 2021-11-08
猜你喜欢
  • 2021-12-28
  • 2021-05-16
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
  • 2022-01-12
  • 2022-01-04
相关资源
相似解决方案