Mysql
 sql >> Datenbank >  >> RDS >> Mysql

Mysql Group In 24-Stunden-Intervallen

Versuchen Sie Folgendes:

SELECT MIN(creation_date), MAX(creation_date), COUNT(*) AS Occurrences 
FROM test
GROUP BY DATE(DATE_SUB(creation_date, INTERVAL 19 HOUR))

Funktionierende Demo:http://sqlfiddle.com/#!2/aa7583/6

Verwenden Sie für den Formatierungsteil Folgendes:

SELECT CONCAT( CONCAT(DATE(DATE_SUB(creation_date, INTERVAL 19 HOUR)),' 19:00:00') , ' - ' , CONCAT(DATE(DATE_ADD(creation_date, INTERVAL 5 HOUR)), ' 18:59:00') ) AS Interval, COUNT(*) AS Occurrences 
FROM test
GROUP BY DATE(DATE_SUB(creation_date, INTERVAL 19 HOUR))