题解 | #查找在职员工自入职以来的薪水涨幅情况#
查找在职员工自入职以来的薪水涨幅情况
http://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
--先查出当前职工的工资,条件是日期to_date=9999-01-01
--再查出入职时的工资,条件是新水表的from_date=员工表的hire_date 以及 两表员工编号相等
--然后在做总的查询,将两个表连接起来取别名s1和s2,在查询语句中可以直接做s1.salary-s2.salary计算growth,s1和s2连接的条件就是员工编号相等
--最后以growth做排序,默认升序
select s1.emp_no,(s1.salary-s2.salary) as growth from
(select emp_no,salary from salaries where to_date='9999-01-01')s1
join
(select s.emp_no,s.salary from salaries s join employees e on s.from_date=e.hire_date and s.emp_no=e.emp_no)s2
on s1.emp_no = s2.emp_no
order by growth;