简体   繁体   English

轨道上的 Ruby:等效轨道查询以获取此信息->

[英]Ruby on rails: equivalent rails query to get this->

How can i get this result from ruby on rails query?我怎样才能从 ruby 在 rails 查询中得到这个结果?

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

Active Relation is amazing.积极的关系是惊人的。 It's just this:就是这样:

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

You should look more into it, it really is great.你应该多看看它,它真的很棒。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM