Group MySQL Data into Arbitrarily Sized Time Buckets
Posted
by Eric J.
on Stack Overflow
See other posts from Stack Overflow
or by Eric J.
Published on 2010-04-05T17:19:42Z
Indexed on
2010/04/05
17:23 UTC
Read the original article
Hit count: 276
How do I count the number of records in a MySQL table based on a timestamp column per unit of time where the unit of time is arbitrary?
Specifically, I want to count how many record's timestamps fell into 15 minute buckets during a given interval. I understand how to do this in buckets of 1 second, 1 minute, 1 hour, 1 day etc. using MySQL date functions, e.g.
SELECT YEAR(datefield) Y, MONTH(datefield) M, DAY(datefield) D, COUNT(*) Cnt FROM mytable GROUP BY YEAR(datefield), MONTH(datefield), DAY(datefield)
but how can I group by 15 minute buckets?
© Stack Overflow or respective owner