我坚持这个, 我有一个文章表,其中包含updated_at和updated_by。我需要编写查询,这将为我提供所选年份所有月份的每位用户更新文章的数量。
谢谢
答案 0 :(得分:0)
试试这个:
在这里,我将2016年作为年份并假设您已current_user
可供
current_user.articles.where("extract(year from updated_at)= ?", 2016).count
答案 1 :(得分:0)
嘿,你可以这样试试:
Article.group("updated_by, date_trunc('month', updated_at)").where("extract(year from updated_at)= ?", 2016).count
它会返回[updated_by, Month_NO] => count