簡體   English   中英

軌道上的 Ruby:等效軌道查詢以獲取此信息->

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

我怎樣才能從 ruby 在 rails 查詢中得到這個結果?

 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

你應該多看看它,它真的很棒。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM