easy solution using not in


  • 0
    B
    select b.id, b.month, sum(a.salary) salary
    from employee a
    join employee b
    on a.id = b.id and a.month <= b.month and a.month+2 >= b.month
    group by b.id, b.month
    having (b.id, b.month) not in 
    (select id, max(month) from employee c group by id)
    order by b.id, b.month desc
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.