薪酬涨幅 = 现在的薪酬 - 入职时的薪酬
需要排除已经离职的人员 (to_date = '9999-01-01')
1. 先求入职时的薪酬,建立带有入职薪酬的表
2. 再 建 现在薪酬表,将已经离职的排除
3. 将2个薪酬相减,得出结果
4. 涨幅升序排序
SELECT s1.emp_no, (s2.salary - s1.salary) AS growth --3.subtract FROM (SELECT e.emp_no, s.salary FROM employees AS e LEFT JOIN salaries AS s ON e.emp_no = s.emp_no WHERE e.hire_date = s.from_date) AS s1 --1. initial salary INNER JOIN (SELECT e.emp_no, s.salary FROM employees AS e LEFT JOIN salaries AS s ON e.emp_no = s.emp_no WHERE s.to_date = '9999-01-01') AS s2 --2. current salary and current employed ON s1.emp_no = s2.emp_no ORDER BY growth ASC --4.ascending