题解 | #查找在职员工自入职以来的薪水涨幅情况#
查找在职员工自入职以来的薪水涨幅情况
https://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5
看到很多人利用最终的工资与初始工资做减法得到增量,所以我就另辟蹊径利用窗口函数做了一版,需要注意的是窗口函数的顺序腰以日期为准否则答案可能会出错,因为我们无法保证工资一直是增加的。
select t1.emp_no, sum(t1.salary - t1.a) as growth from (select emp_no, salary, lag(salary,1,0) over (partition by emp_no order by to_date ASC) as a from salaries ) as t1 where t1.a != 0 and t1.emp_no in (select distinct emp_no from salaries where to_date = "9999-01-01") group by t1.emp_no order by growth