代码语言: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;