SELECT w2.Id from Weather w1, Weather w2 where dateDiff(w1.Date,w2.Date)=1 and w2.Temperature>w1.Temperature
because dateDifference gives the absolute output so either w1 date is later or w2 it always gives 1 for 1 day difference. for example:
if w1.date =1990-05-02
this gives 1...
this also gives 1 ..
and you are printing id of only w2 instance of weather..
You want w1 be the earlier date and w2 be the later date, right? For example the 5th and the 6th of a month? Do you think
5 - 6 = 1? It's
-1. So don't ask for
dateDiff(w1.Date,w2.Date) = 1
dateDiff(w2.Date,w1.Date) = 1
dateDiff(w1.Date,w2.Date) = -1
You're wrong, it doesn't give the absolute value (unless it's already non-negative, of course).
Well, when I google "SQL Datediff", most of the websites show the difference between two dates will be an absolute value. The function also takes a third parameter indicating the time unit which doesn't apply for Datediff in mySQL, i.e. Datediff(day, "2015-10-02", "2015-10-03") = 1.
I had googled as well and couldn't find one with absolute value. Can you show one of those?
My mistake saying it takes absolute value. It's just the order of the dates is opposite for SQL server. I guess the asker just also looked at the Datediff example for SQL server.
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.