题解 | #获取当前薪水第二多的员工的emp_no以及其对应的薪水salary#
获取当前薪水第二多的员工的emp_no以及其对应的薪水salary
http://www.nowcoder.com/practice/8d2c290cc4e24403b98ca82ce45d04db
法一: 窗口函数(由于可能有相同工资的多个人,所以不用rank(),而用dense_rank())
select emp_no, salary
from (
select emp_no, salary,
dense_rank() over(order by salary desc) as posn
from salaries
)rk
where rk.posn = 2
order by emp_no
法二:order by + limit(由于可能有相同工资的多个人,须在salary前面加distinct)
select emp_no, salary
from salaries
where salary = (
select distinct salary
from salaries
order by salary desc
limit 1,1
)
order by emp_no