题解 | #查找在职员工自入职以来的薪水涨幅情况#

查找在职员工自入职以来的薪水涨幅情况

http://www.nowcoder.com/practice/fc7344ece7294b9e98401826b94c6ea5

窗口函数

select
t.emp_no
,(t.last_salary - t.first_salary) growth
from
(
select
emp_no
,first_value(salary) over(partition by emp_no order by from_date) first_salary
,last_value(salary) over(partition by emp_no order by from_date) last_salary
,last_value(to_date) over(partition by emp_no order by from_date) last_date
from salaries
) t
where t.last_date = '9999-01-01'
order by growth

全部评论
select emp_no, max(salary) -min(salary) as growth from (select emp_no,salary,from_date, min(from_date) over(partition by emp_no) as min_fromdate, max(from_date) over(partition by emp_no) as max_fromdate from salaries where emp_no in (select distinct emp_no from salaries where to_date='9999-01-01'))t where t.from_date=t.min_fromdate or t.from_date=t.max_fromdate group by emp_no order by growth 我给搞复杂了,没想到first_value这个
点赞 回复 分享
发布于 2021-11-23 13:27

相关推荐

给🐭🐭个面试机会...:我擦seed✌🏻
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
3
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务