开发者

How to get a summary of Posts by month? i.e. month with count

开发者 https://www.devze.com 2023-01-27 16:06 出处:网络
I need to get a list of months that contain Posts in the Post table, along with the count of posts for the month.

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)')
0

精彩评论

暂无评论...
验证码 换一张
取 消