Reputation: 266998
I need to get a list of months that contain Posts in the Post table, along with the count of posts for the month.
e.g.
JAN 11
FEB 23
MAR 4
So some months won't show up if there are no posts for that month.
My post model is like:
Post (ID, TITLE, DATE_CREATED)
I don't need the actual posts returned, just the MONTH and the COUNT for the month.
Upvotes: 1
Views: 267
Reputation: 53158
Easiest way probably (rails2 not sure about 3 but should be similar):
Post.count(:group=>'MONTH(DATE_CREATED)')
Upvotes: 3