分析:
本题查找自入职以来的薪水涨幅,所以必须知道当前的薪水,入职的薪水,所以构建两个表
代码:
select now.emp_no, (now.salary - past.salary) as growth
from (select s.emp_no,s.salary
from salaries as s join employees as e
on s.emp_no = e.emp_no and s.to_date = ‘9999-01-01’) as now,
#当前薪水
(select s.emp_no,s.salary
from salaries as s join employees as e
on s.emp_no = e.emp_no and e.hire_date = s.from_date ) as past
#入职薪水
where now.emp_no = past.emp_no
order by growth