Answer the question
In order to leave comments, you need to log in
How to select data for each hour from SQL database?
Good day to all. I have a table with fields - (id, temp, hum, date). An entry is added to it every 5 minutes. Help write a query that would display temp, hum and date for each hour for the current day. That is, there should be 24 entries. I am attaching an image of the table for clarity. Thanks in advance.
Answer the question
In order to leave comments, you need to log in
Something like this
...
WHERE
DATE(date) = CURDATE()
GROUP BY
EXTRACT(HOUR FROM date)
ORDER BY
EXTRACT(HOUR FROM date)
If the data is not for one day and you need to get data for the entire period, then something like this:
SELECT
DATE(table.dattim) AS DD,
HOUR(table.dattim) AS HH,
AVG(table.value) AS AVG_VALUE
FROM table
GROUP BY DD, HH
ORDER BY DD, HH
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question