题解 | #获取每个部门中当前员工薪水最高的相关信息#

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

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

先找到最大薪水

select max(salary) from salaries where to_date = '9999-01-01' 

然后将上面的结果作为一个条件,查找第二大!

select max(salary) from salaries where to_date = '9999-01-01' and salary < (select max(salary) from salaries where to_date = '9999-01-01') 

最后联结两个表就可以得到想要的结果!

SELECT a.emp_no, b.salary,a.last_name,a.first_name from employees a inner join salaries b 
on a.emp_no = b.emp_no
where to_date = '9999-01-01' 
and b.salary = 
(
    select max(salary) from salaries where to_date = '9999-01-01' 
    and salary < (select max(salary) from salaries where to_date = '9999-01-01')
)
全部评论

相关推荐

评论
1
收藏
分享

创作者周榜

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