【发布时间】:2015-10-30 23:34:33
【问题描述】:
参考这个: Is there any difference between GROUP BY and DISTINCT
Given a table that looks like this:
name
------
barry
dave
bill
dave
dave
barry
john
This query:
SELECT name, count(*) AS count FROM table GROUP BY name;
Will produce output like this:
name count
-------------
barry 2
dave 3
bill 1
john 1
对于 ActiveModel 使用 COUNT 执行 GROUP BY 的正确 Rails 约定是什么?
【问题讨论】:
-
Table.all.group(:name).count
标签: sql ruby-on-rails ruby postgresql activerecord