Ruby on rails:等价的rails查询得到这个 - >

时间:2011-07-17 07:41:01

标签: ruby-on-rails

如何在rails查询中从ruby获取此结果?

 select post_id, count(post_id)
 from comments
 group by post_id
 order by count(post_id) desc
 limit 5

1 个答案:

答案 0 :(得分:0)

积极的关系是惊人的。就是这样:

Comment.select("post_id, COUNT(post_id)").group("post_id").order("COUNT(post_id) DESC").limit(5).all

你应该更多地了解它,它真的很棒。