Ruby on rails RubyonRails:等效于rails查询以获取此->;

Ruby on rails RubyonRails:等效于rails查询以获取此->;,ruby-on-rails,Ruby On Rails,如何从RubyonRails查询中获得这个结果 select post_id, count(post_id) from comments group by post_id order by count(post_id) desc limit 5 积极的关系是惊人的。就是这个, Comment.select("post_id, COUNT(post_id)").group("post_id").order("COUNT(post_id) DESC").limit(5).all 你应该

如何从RubyonRails查询中获得这个结果

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

积极的关系是惊人的。就是这个,

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

你应该多看看,这真的很好。

我建议你接受一些答案,然后看看这本指南。我想得到那些评论最多的帖子。谢谢jesse,但我想得到那些帖子,这些帖子都有我从评论中得到的帖子id。选择(“帖子id,计数(帖子id)”)。分组(“帖子id”)。顺序(“计数(帖子id)描述”)。限制(5) .好吧,我怎么能在一个查询中做到这一点?我不理解你的评论。