Here is the data that I want to work with
create table weather(
id int,
recorddate date,
temp int,
primary key (id)
);
insert into weather values (1, '2015-01-01', 10);
insert into weather values (2, '2015-01-02', 15);
insert into weather values (3, '2015-01-03', 20);
I want to select a date that has a higher temp than the previous day, and I used this query:
select id
from weather a
where id = (select id from weather b where datediff(a.recorddate, b.recorddate) = -1 and b.temp > a.temp)
The query returns 0 record and I know the logic of the subquery is correct, but for some reason it does not work.
Update
I am not looking for an alternative way of writing this query, I want to know what is wrong with the query above?
Update
The part that I got wrong is that I was thinking to assign a value to id by writing where id=...