S
S
semki0962018-03-14 11:15:39
MySQL
semki096, 2018-03-14 11:15:39

How to sample data for the last 24 hours in hourly mode?

For example, you need to display all the data for the last day but ... from 00 to 6 hours, from 6 to 12 hours, from 12 to 18, from 10 to 24. How to build such a query? Or one request and then how to process it in php? (again - how to do it?)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
Boris Korobkov, 2018-03-14
@semki096

SELECT
   FLOOR(HOUR(date_time) / 6) AS period, 
   AVG(temperature) AS avg_temperature 
FROM table_name 
WHERE date_time > DATE_SUB(NOW(), INTERVAL 1 DAY)
GROUP BY FLOOR(HOUR(date_time) / 6)

L
Lazy @BojackHorseman MySQL, 2018-03-14
Tag

group by case when hour(<field>) between ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question