数据:https://blog.csdn.net/qq_38560351/article/details/106331612
1. 查找当前薪水(to_date=‘9999-01-01’)排名第二多的员工编号emp_no、薪水salary、last_name以及first_name
解法一:使用order by 和 limit完成
select a.emp_no,b.salary,a.last_name,a.first_name
from employees as a
join salaries as b on a.emp_no = b.emp_no
where 1=1
and b.to_date = '9999-01-01'
order by b.salary desc
limit 1,1;
解法二:不使用order by 和 limit完成
select a.emp_no,max(b.salary),a.last_name,a.first_name
from employees as a
join salaries as b on a.emp_no = b.emp_no
where 1=1
and b.to_date = '9999-01-01'
and b.salary not in(
SELECT max(salary) from salaries
where to_date = '9999-01-01');