题解 | 获取当前薪水第二多的员工的emp_no以及其对应的薪水salary
获取当前薪水第二多的员工的emp_no以及其对应的薪水salary
https://www.nowcoder.com/practice/8d2c290cc4e24403b98ca82ce45d04db
1-- select emp_no ,salary from salaries where to_date = '9999-01-01' and salary = (select salary from salaries where to_date = '9999-01-01' group by salary order by salary desc limit 1,1) order by emp_no 2-- select emp_no,salary from( select emp_no, salary,dense_rank()over(order by salary desc)rk from salaries where to_date='9999-01-01') e where e.rk=2 order by emp_no 第一思路窗口函数,直接排名,必须用dense_rank应对多个相同薪水的情况 第二思路用分组group by,直接对salary去重了,通过limit获取第二多,需注意内外都需对时间过滤