I have a table which is updated every 10 seconds with data. I need to get an average for 10 minutes, for 24 hours for a particular date.
I tried doing this and increment the time by 10 mins through php.
select AVG(active_energy), date_time from energy_readings where date_time between "2016-11-02 00:00:00" and "2016-11-02 00:00:00"+ INTERVAL 10 MINUTE;
and then
select AVG(active_energy), date_time from energy_readings where date_time between "2016-11-02 00:10:00" and "2016-11-02 00:10:00"+ INTERVAL 10 MINUTE;
for 24 hours.
It works, but it takes too much load on my database server.
Is there a single mysql query that I can use which will give me 10 min averages for 24 hours for a particular day?
Here is one method to get a row for every 10 minutes of data:
select date(date_time), hour(date_time), floor(minute(date_time) / 6),
avg(active_energy)
from energy_readings
where date_time >= '2016-11-02' and datetime < '2016-11-03'
group by date(date_time), hour(date_time), floor(minute(date_time) / 6)
order by min(date_time);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.