select t1.emp_no,t1.salary-t2.salary growth from
(
#在职员工现在的工资表
select a.emp_no,b.salary
from employees a
left join salaries b
on a.emp_no=b.emp_no
where b.to_date='9999-01-01'
) t1 join
(
#在职员工入职的工资表
select a.emp_no,b.salary
from employees a
left join salaries b
on a.emp_no=b.emp_no
and a.hire_date=b.from_date
) t2
on t1.emp_no=t2.emp_no
order by growth
;

京公网安备 11010502036488号