Group mysql query by 15 min intervals

前端 未结 10 880
醉梦人生
醉梦人生 2020-11-27 03:09

I\'ve got a monitoring system that is collecting data every n seconds (n is approximately 10 but varies). I\'d like to aggregate the collected data by 15 minute intervals.

10条回答
  •  忘掉有多难
    2020-11-27 04:00

    I started with the answer given above by unutbu but didn't get what I needed and had to add a bit to it.

    Select Created, from_unixtime(FLOOR(UNIX_TIMESTAMP(Created)/(15*60))*(15*60)) GroupTime, COUNT(*) as Cnt FROM issue i GROUP BY GroupTime

    This code divides by the 900 seconds in a 15 minute span then floors the value and multiplies it back up by 900, essentially rounding down to the nearest 15 minute increment.

提交回复
热议问题