题解 | 查找在职员工自入职以来的薪水涨幅情况
WITH a AS ( SELECT emp_no, salary FROM salaries WHERE to_date = '9999-01-01' ), b AS ( SELECT s.emp_no, s.salary FROM salaries s JOIN employees e ON s.emp_no = e.emp_no WHERE s.from_date = e.hire_date ) SELECT a.emp_no, a.salary - b.salary AS growth FROM a INNER JOIN b ON a.emp_no = b.emp_no order by growth;
生成两张表,根据两张表的结果做。