<分区>
我有以下内容:
Question.group('date(created_at), type').count
返回:
# => {"5"=>4, "2"=>3, "1"=>4, "4"=>1, "3"=>1}
代替:
# => {["2013-12-02", "5"]=>3, ["2013-12-02", "2"]=>2, ["2013-12-02", "1"]=>2}...
我做错了什么?
<分区>
我有以下内容:
Question.group('date(created_at), type').count
返回:
# => {"5"=>4, "2"=>3, "1"=>4, "4"=>1, "3"=>1}
代替:
# => {["2013-12-02", "5"]=>3, ["2013-12-02", "2"]=>2, ["2013-12-02", "1"]=>2}...
我做错了什么?
最佳答案
您需要使用方括号将日期和类型组合在一起。试试这个:
Question.group(["date(created_at)", :type]).count
简单拆分传递给group
的参数会起作用,但我认为以上内容更清楚:
Question.group("date(created_at)", :type).count
两者都会给你这样的结果:
["<date>", <type>] => count
关于ruby-on-rails - ActiveRecord group by 乘法字段和计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20448602/
相关文章:
android - 使用 Redis 服务器将数据从 android 发布到 rails
ruby-on-rails - : Drools (www. drools.org 的 Ruby 替代品)一个业务逻辑集成平台
ruby-on-rails - 在开发环境中覆盖 ActionMailer 的邮件地址
postgresql - 从 JavaDB 迁移到 PostgreSQL 并且无法再访问数据库
postgresql - 复制 postgresql 数据库的更快方法(或最佳方法)
ruby - 在哪里存储带有 ORM 的列描述(尤其是 Sequel)?