Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL Raggruppa per intervallo specifico di 24 ore

Puoi farlo sottraendo 5,5 ore e aggregando per data:

select date_add(date(timestamp - interval (5*60 + 30) minute), interval (5*60 + 30)  minute) as interval_start,
       date_add(date(timestamp - interval (5*60 + 30) minute), interval (24*60 + 5*60 + 30)  minute) as interval_end,
       count(*) as cnt
from t
group by date(timestamp - interval (5*60 + 30) minute)
order by interval_start;