我目前有以下查询
User.sum(:experience, :group => "clan", :conditions => ["created_at >= ? and created_at <= ?", "2010-02-15", "2010-02-16"])
我希望从大多数经验中列出的经验回归前50名部落,只返回经验最少的前50名。如何修改查询以实现该结果。我知道我需要:limit =&gt; 50限制查询,但如果我添加:order =&gt; “clan DESC”我得到错误列“users.experience”必须出现在GROUP BY子句中或用于聚合函数
答案 0 :(得分:0)
您需要在订单子句中重复计算
User.sum(:experience, :group => "clan", :order=> "sum(experience) DESC", :limit => 50, :conditions => ["created_at >= ? and created_at <= ?", "2010-02-15", "2010-02-16"])