I have a set or records and I want to count and group them by a certain range e.g. I want to count the records that were created by groups of X days
e.g. SELECT COUNT(*) FROM `table` GROUP BY /*`created` 3 days/*
I have a set or records and I want to count and group them by a certain range e.g. I want to count the records that were created by groups of X days
e.g. SELECT COUNT(*) FROM `table` GROUP BY /*`created` 3 days/*
Here is an example with dates.
Thanks @Ronnis, I use your example and finally solve my problem.
And there is a small mistake I found, in example, I add one row
Now I get:
As you can see that days divide into 2, 3, 3, 3, 2 which not what I expected.
I change SQL as
Just get datediff from created to start date, and now I get:
That might be more suitable.
You can do something like
SELECT COUNT(*) FROM table GROUP BY FLOOR(created / 3)
... I think.
Although if
created
is a date field, you'll have to do a little more jiggering to get it into a number value for this to work.