首页 > 其他 > 详细

第二高的薪水-leetcode

时间:2020-06-09 14:25:23      阅读:43      评论:0      收藏:0      [点我收藏+]

第二高的薪水


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

1. 地址

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

第二高的薪水-leetcode

原文:https://www.cnblogs.com/wudanyang/p/13071979.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!