题解 | #查找在职员工自入职以来的薪水涨幅情况#
查找在职员工自入职以来的薪水涨幅情况
https://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
select t1.emp_no, (t1.salary - s.salary) as growth
from (
select e.emp_no, e.hire_date, s.salary
from employees e
join salaries s
on e.emp_no = s.emp_no
where s.to_date = '9999-01-01'
) t1
join salaries s
on t1.emp_no = s.emp_no and t1.hire_date = s.from_date
order by growth;
- 通过两表联查找到在职员工,同时保存在职员工的目前薪资,得到表t1
- 通过t1与salaries两表联查,找出在职员工上任时间对应的薪资,其与t1中在职员工的目前薪资的差值即为growth
- 排序

