A simple straightforward solution and it's very fast


  • 6
    W
    select w1.Id Id from Weather w1, Weather w2 where datediff(w1.Date,w2.Date)=1 and w1.Temperature>w2.Temperature

  • 0
    G

    select w1.Id Id from Weather w1, Weather w2 where datediff(w1.Date,w2.Date)=1 and w1.Temperature>w2.Temperature


  • 0
    G

    This is cool, but wondering why DATEDIFF doesn't need an argument specifying the unit of difference (i.e. DAY)? How does it know we're not subtracting an hour or a month instead?

    I implemented it this way:

    SELECT W1.Id FROM Weather AS W1, Weather AS W2
    WHERE W1.Temperature > W2.Temperature AND DATEDIFF(W1.Date, W2.Date) = 1;
    

Log in to reply
 

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