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

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

https://www.nowcoder.com/practice/8d2c290cc4e24403b98ca82ce45d04db

#法一:窗口函数,先排名,再选出第二的
select emp_no ,salary
from (
select emp_no ,salary,rank()over(order by salary desc) rk
from salaries )a
where rk=2

#法2:找出第二高的薪水,再筛选
select emp_no,salary
from salaries
where salary =
(select salary from salaries 
order by salary desc
limit 1,1)

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务