考虑以下模型:Ruby On Rails使用sum和group进行查询?
class Vote < ActiveRecord::Base
attr_accessible :user_id, :vote_for_id, :voting_category_id, ,:points_earned
belongs_to :user
belongs_to :vote_for
belongs_to :voting_category
我想知道如何使一个PostgreSQL数据库,返回一个领导者板的查询。 换句话说,每个用户的points_earned总数,从第一个到最后一个排序?
到目前为止,我有:
Votes.sum(:points_earned).group(:user_id, :id).order(:points_earned)
在此先感谢
这是什么给你? – rogerdpack