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

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

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

select
emp_no,
growth
from(
    select
emp_no,
salary - lag(salary,1,null) over(partition by emp_no)  growth
from
    (
        select
            emp_no,
            salary,
            from_date,
            to_date,
            row_number() over (
                partition by
                    emp_no
                order by
                    from_date
            ) rk,
            max(to_date) over (
                partition by
                    emp_no
            ) isin,
            count(emp_no)over (
                partition by
                    emp_no
            ) n
        from
            salaries
    ) t
    where isin = '9999-01-01' and (rk = 1 or rk = n) 

) a where growth is not null
order by growth

窗口函数

全部评论

相关推荐

不愿透露姓名的神秘牛友
10-04 05:12
瑞雪兆丰年_:可以贴个超级大的校徽,以防HR眼拙
点赞 评论 收藏
分享
10-31 13:04
南华大学 Java
嵌入式的小白:很多面试,面试前不会去打扰cto的,但一般cto不会在这些小事上刷人,只能说这个cto比较操心,啥重要不重要,紧急不紧急的,估计都会过问,平淡看待吧
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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