How do I generate a series of hourly averages in MySQL?

前端 未结 3 1102
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 10:23

I\'ve got data in ten minutes intervals in my table:

2009-01-26 00:00:00      12
2009-01-26 00:10:00      1.1
2009-01-26 00:20:00      11
2009-01-26 00:30:00         


        
3条回答
  •  既然无缘
    2020-12-15 11:18

    It's unclear whether you want the average to be aggregated over days or not.

    If you want a different average for midnight on the 26th vs midnight on the 27th, then modify Mabwi's query thus:

    SELECT AVG( value ) , thetime
    FROM hourly_averages
    GROUP BY DATE( thetime ), HOUR( thetime )
    

    Note the additional DATE() in the GROUP BY clause. Without this, the query would average together all of the data from 00:00 to 00:59 without regard to the date on which it happened.

提交回复
热议问题