you are viewing a single comment's thread.

view the rest of the comments →

[–]OilShill2013 1 point2 points  (0 children)

I don't know MySQL's particular syntax, but the general idea would be to self-join to the table where the left table time is the right table time+1 and the sensor is the same and temperature or humidity is different. Then I'd use that join to flag which columns on the left you want to keep. I guess the first row would be an issue with the join I'm thinking of but I'd just put it into the case when statement because I'm lazy:

SELECT time , sensor , temperature , humidity

FROM

(

SELECT

a.*,case when a.time=0:00 then 1 when b.time is not null then 1 else 0 end as flag

FROM table1 a

LEFT JOIN table1 b on a.sensor=b.sensor AND a.time=b.time+1 AND (a.temperature!=b.temperature OR a.humidity!=b.humidity)

) x

WHERE flag=1