Group mysql query by 15 min intervals

前端 未结 10 727
醉梦人生
醉梦人生 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 03:51

    I was not satisfied by GROUP BY.

    SELECT   datetime
    FROM     table
    WHERE MOD(MINUTE(TIME(datetime)),15) = 0 AND SECOND(TIME(datetime)) = 0;
    
    0 讨论(0)
  • 2020-11-27 03:53

    THis Work for me

    SELECT CONCAT (
            YEAR(transactionDate)
            ,'-'
            ,MONTH(transactionDate)
            ,'-'
            ,DAYOFMONTH(transactionDate)
            ,' '
            ,HOUR(transactionDate)
            ,':'
            ,((floor((MINUTE(transactionDate) / 15)) + 1) * 15) - 1
            ,':59'
            ) AS tmp1
        ,count(*)
    FROM tablename
    GROUP BY tmp1 limit 20;
    
    0 讨论(0)
  • 2020-11-27 03:58

    Change "15" to whatever interval you want.

    select count(*),
    CONCAT(HOUR(col_date),":",(MINUTE(create_date) div 15)*15) as date
    from tablename
    GROUP BY date
    ORDER BY col_date ASC;
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题