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

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

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

with b as (
    select distinct emp_no
    from salaries
    where to_date = '9999-01-01'
),
a as (
    select b.emp_no,salary,rank() over(partition by b.emp_no order by from_date) as rk
    from b left join salaries
    on b.emp_no = salaries.emp_no
),
c as (
    select emp_no,max(rk) as maxrk,min(rk) as minrk
    from a
    group by emp_no
),
d as (
    select c.emp_no,a1.salary - a2.salary as growth
    from c left join a as a1
    on c.emp_no = a1.emp_no and c.maxrk = a1.rk
    left join a as a2
    on c.emp_no = a2.emp_no and c.minrk = a2.rk
)

select *
from d
order by growth

怎么还有工资先涨后降的操作啊

全部评论

相关推荐

头像
11-27 14:28
长沙理工大学
刷算法真的是提升代码能力最快的方法吗? 刷算法真的是提升代码能力最快的方法吗?
牛牛不会牛泪:看你想提升什么,代码能力太宽泛了,是想提升算法能力还是工程能力? 工程能力做项目找实习,算法也分数据结构算法题和深度学习之类算法
点赞 评论 收藏
分享
巧克力1:双选会不如教室宣讲会
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务