I have to make a query with the first data close to 8 in the morning per day but sometimes the one at 8 is not there, so I would need the next one.
I use this query
SELECT datos.id_estacion, datos.fecha, hora, datos.valor
from datos
where id_estacion=1
and tipo_sensor=3
and day(fecha)=1
and hour(hora) in (8,9)
order by fecha, hora
limit 10
And I get this data
fecha hors valor
2016-01-01 08:45:00 1147,97
2016-01-01 09:00:00 1147,96
2016-01-01 09:45:00 1147,96
2016-02-01 08:00:00 1150,95
2016-02-01 08:15:00 1150,95
2016-02-01 08:30:00 1150,95
2016-02-01 08:45:00 1150,96
2016-02-01 09:00:00 1150,96
2016-02-01 09:15:00 1150,96
2016-02-01 09:30:00 1150,96
But I need the closest to 8
01/01/2016 8:45:00 1147,97
01/02/2016 8:00:00 1150,95
Thanks!