题解 | #查找在职员工自入职以来的薪水涨幅情况#
查找在职员工自入职以来的薪水涨幅情况
http://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
首先组建每个员工入职的emp_no,及入职时的薪水,
然后组建在职员工也就是to_date='9999-01-01'的薪水,
求差即可算出入职到现在的薪水涨幅情况
SELECT t1.emp_no, t1.salary-t2.salary AS growth FROM (SELECT t1.emp_no, t2.salary FROM employees AS t1 INNER JOIN salaries AS t2 ON t1.emp_no=t2.emp_no WHERE to_date='9999-01-01' ) AS t1 INNER JOIN (SELECT t1.emp_no, t2.salary FROM employees AS t1 INNER JOIN salaries AS t2 ON t1.emp_no=t2.emp_no AND t1.hire_date=t2.from_date) AS t2 ON t1.emp_no=t2.emp_no ORDER BY growth ASC