Solution w/o Large Self-Join


  • 0
    M
    SELECT
        wt2.Id
    FROM
        Weather wt1
            INNER JOIN
        Weather wt2 ON wt2.Date = DATE_ADD(wt1.Date, INTERVAL 1 DAY)
    WHERE
        wt2.Temperature > wt1.Temperature
    

    The above query should run faster when querying large tables because it doesn't create n^2 intermediate rows during the self join.


Log in to reply
 

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