题解 | #查询员工当前薪水信息,并找出薪水排名第二多的员工信息#
#查询员工当前薪水信息,并找出薪水排名第二多的员工信息
#1.查询当前员工的最高薪水
select max(salary) from salaries where to_date='9999-01-01'
#2.把最高薪水的员工排除掉,从剩下的员工信息中找出员工的最高薪水,此时这个最高薪水就是第二多薪水
select max(salary) from salaries where salary < (select max(salary) from salaries where to_date='9999-01-01')
#3.根据题目要求返回结果
select e.emp_no,salary,last_name,first_name from employees as e inner join salaries as s on e.emp_no=s.emp_no and to_date='9999-01-01' where salary = (select max(salary) from salaries where salary < (select max(salary) from salaries where to_date='9999-01-01'));