0

I'm tryin without success to get datas from a database between now and 7:00 am

I've tried this, it returns datas but it's the wrong ones for 7:00

SELECT *, MIN(AMBIENT_TEMPERATURE) AS min_temp, 
       MAX(AMBIENT_TEMPERATURE) AS max_temp
FROM WEATHER_MEASUREMENT
WHERE DATE(CREATED) = CURDATE() AND TIME(CREATED)>='07:00:00'

I think this is pretty easy but still too difficult for me.

thanks.

jerome

Deepesh
  • 6,138
  • 1
  • 24
  • 41
JEROME C
  • 1
  • 1

1 Answers1

0

Just as you used the DATE function to determine if the row was from the correct day, use the HOUR function to determine if the row is from the correct hour.

I don't really understand from your question which rows you are trying to get back, all of the ones from today in the 7am hour? All of the ones from today before 7am? It isn't clear. This will give you the ones before 7am: SELECT *, MIN(AMBIENT_TEMPERATURE) AS min_temp, MAX(AMBIENT_TEMPERATURE) AS max_temp FROM WEATHER_MEASUREMENT WHERE DATE(CREATED) = CURDATE() AND HOUR(CREATED)<7

Cargo23
  • 3,064
  • 16
  • 25