题解 | #获取当前薪水第二多的员工的emp_no以及其对应的薪水salary#

获取当前薪水第二多的员工的emp_no以及其对应的薪水salary

http://www.nowcoder.com/practice/c1472daba75d4635b7f8540b837cc719

SELECT e.emp_no, s.salary, e.last_name, e.first_name from employees e left join salaries s on e.emp_no=s.emp_no where s.salary =( select max(s2.salary) from salaries s2 where s2.salary < (select max(salary) from salaries where to_date = '9999-01-01') and s2.to_date='9999-01-01');

因为不能用order by,所以选择用max对数据进行筛选,首先把最大的工资筛选掉,即(select max(salary) from salaries where to_date = '9999-01-01'),to_date必须要因为有的员工可能不在了,但工资是第一名;再利用max筛选出最大值即为第二名的工资,to_date 同理

全部评论

相关推荐

每晚夜里独自颤抖:你cet6就cet6,cet4就cet4,你写个cet证书等是什么意思。专业技能快赶上项目行数,你做的这2个项目哪里能提现你有这么多技能呢
点赞 评论 收藏
分享
自由水:笑死了,敢这么面试不敢让别人说
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务