Why is subtracting 1 directly from Date not working, but subdate(a.Date,1) works?
My code is
select W1.Id from Weather as W1, Weather as W2 where W1.Date-1 = W2.Date and W1.Temperature> W2.Temperature
it only passed 13/14 cases.
However, when I changed
sub(W1.Date,1) in the where clause, it worked. What is fundamental difference?
Subtracting treats date as number, shouldn't be used in date calculation.
SELECT DATE('2015-02-01')-1, SUBDATE(DATE('2015-02-01'),1)
Actually that should be
DATE(DATE('2015-02-01')-1) because in the
WHERE clause it is compared to a
DATE. Notice how
20150200 smoothly converts to a correct date if squeezed through another
Sadly in general you're correct
20150199 converts to
Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.