AC Solution

  • 3
    SELECT EA.Id, 
           Sum(EB.salary) AS Salary 
    FROM   (SELECT E1.* 
            FROM   employee E1 
                   LEFT JOIN (SELECT id, 
                                     Max(month) AS month 
                              FROM   employee 
                              GROUP  BY id) E2 
                          ON = 
            WHERE  E1.month < E2.month) EA 
           LEFT JOIN employee EB 
                  ON = 
    WHERE  EB.month <= EA.month 
           AND EB.month >= EA.month - 2 
    GROUP  BY, 
    ORDER  BY, 
              month DESC 

  • 0

    I thought the left join after E1 should be inner join.

Log in to reply

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