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

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

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

窗口函数

全部评论

相关推荐

代码飞升:别这样贬低自己,降低预期,放平心态,跟昨天的自己比。做好自己,反而会效率更高心态更好,加油兄弟
点赞 评论 收藏
分享
双尔:你就写拥有ai开发经历,熟练运用提示词,优化ai,提高ai回答质量
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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