按两列分组计数

时间:2013-12-04 18:57:42

标签: ruby-on-rails group-by arel

我想将两个不同的列分组并将计数作为嵌套哈希值。

User.group('role').count => gives me {"admin" => 10, "user" => 15}

如何编写查询以获得此类结果(按角色和性别分组)

{"admin" => {"male" => 2, "female" => 3}, "user" => {"male" => 4, "female" => 4}}

0 个答案:

没有答案