Leetcode 579. 查询员工的累计薪水(lag 前瞻函数 查看前几行 分组聚合经典例子)

2021-04-09 14:53:53 浏览数 (1)

代码语言:javascript复制
select id,month,salary ifnull(l1,0) ifnull(l2,0) salary
    from 
    (select *,lag(salary,1) over(partition by id order by month ) l1,
    lag(salary,2) over(partition by id order by month)l2,
    rank() over(partition by id order by month desc) r
    from employee)A
    where r>1
    order by 1,2 desc;

0 人点赞