题解 | #查找在职员工自入职以来的薪水涨幅情况#
查找在职员工自入职以来的薪水涨幅情况
http://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
首先找出当前员工号和工资形成一个表b,然后找出入职时员工号和工资形成一个表a, 最后两表合并后求差排序。
select a.emp_no, (b.salary-a.salary) Growth
from (select e.emp_no, s.salary
from employees e
left join salaries s
on e.emp_no = s.emp_no
where s.to_date='9999-01-01') b
join
(select e.emp_no, s.salary
from employees e
left join salaries s
on e.emp_no = s.emp_no
where s.from_date=e.hire_date) a
on b.emp_no=a.emp_no
order by Growth;