AC solution without join


  • 0
    F
    SELECT id, 
           month, 
           (SELECT Sum(salary) 
            FROM   employee 
            WHERE  month <= e.month 
                   AND month >= e.month - 2 
                   AND id = e.id)AS salary 
    FROM   employee e 
    WHERE  ( id, month ) NOT IN (SELECT id, 
                                        Max(month) AS month 
                                 FROM   employee 
                                 GROUP  BY id) 
    ORDER  BY id ASC, 
              month DESC; 
    

Log in to reply
 

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