开发者

Ruby on Rails Query Help

开发者 https://www.devze.com 2022-12-20 15:15 出处:网络
I currently have the following query User.sum(:experience, :group => \"clan\", :conditions => [\"created_at >= ? and created_at <= ?\", \"2010-02-15\", \"2010-02-16\"])

I currently have the following query

User.sum(:experience, :group => "clan", :conditions => ["created_at >= ? and created_at <= ?", "2010-02-15", "2010-02-16"])

I want to return the top 50 clans in terms of experience listed f开发者_Go百科rom most experience to least experience with only the top 50 in experience returning. How would I modify the query to achieve that result. I know I'll need :limit => 50 to limit the query but if I add :order => "clan DESC" I get the error column "users.experience" must appear in the GROUP BY clause or be used in an aggregate function


You need to repeat the calculation in the order clause

User.sum(:experience, :group => "clan", :order=> "sum(experience) DESC", :limit => 50, :conditions => ["created_at >= ? and created_at <= ?", "2010-02-15", "2010-02-16"])
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号