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

题目描述:

获取当前(to_date='9999-01-01')薪水第二多的员工的emp_no以及其对应的薪水salary
1 CREATE TABLE `salaries` (
2 `emp_no` int(11) NOT NULL,
3 `salary` int(11) NOT NULL,
4 `from_date` date NOT NULL,
5 `to_date` date NOT NULL,
6 PRIMARY KEY (`emp_no`,`from_date`));

 

难易程度:

中等

 

解答:

用limit巧解

1 select emp_no,salary
2 from salaries
3 where to_date='9999-01-01'
4 and salary < (select max(salary) from salaries)
5 order by salary desc
6 limit 1

 

 

 

posted @ 2020-09-30 11:23  Python小白白  阅读(127)  评论(0)    收藏  举报