Lizard Lizard - 10 months ago 60
SQL Question

Mysql Can you group by a range?

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/*



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.