Here is the two method, both with inner join. Which is faster why?


  • 0
    J
    Select a.Id 
    From Weather a join Weather b on DATEDIFF(a.Date, b.Date) = 1
    Where a.Temperature > b.Temperature
    

    And

    Select a.Id 
    From Weather a join Weather b
    Where a.Temperature > b.Temperature and DATEDIFF(a.Date, b.Date) = 1
    

    Which is faster? Why?

    I submit both of the two method, and the second is a little faster than the first one. But I do not know why.


  • 0
    Y

    because the sql string will be compiled from the end.


Log in to reply
 

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