How to get a summary of Posts by month? i.e. month with count
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.
Easiest way probably (rails2 not sure about 3 but should be similar):
Post.count(:group=>'MONTH(DATE_CREATED)')
精彩评论