题解 | #查找在职员工自入职以来的薪水涨幅情况#
查找在职员工自入职以来的薪水涨幅情况
https://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
select b.emp_no, c.salary - b.salary as growth #作差即为变化 from( select e.emp_no, s1.salary from salaries s1 join employees e on s1.emp_no = e.emp_no where s1.from_date = e.hire_date)b #先找出入职时的工资是多少,有hire_date很容易 join (select emp_no, salary from (select emp_no, salary, rank()over(order by to_date desc) ranks from salaries)a where ranks = 1)c #找出目前的工资是多少,注意这里考虑了离职的情况,即找to_date最大的记录就行了 on b.emp_no = c.emp_no order by c.salary - b.salary
这里感觉找出目前工资可以优化,lz是学了一周的小白就不深究了