Created
September 23, 2012 03:32
-
-
Save phaedryx/3768744 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class User < ActiveRecord::Base | |
has_many :items | |
... | |
def self.ranked(year) | |
select("rank() OVER(ORDER BY SUM(items.amount) DESC), users.*, SUM(items.amount) AS grand_total") | |
.joins(:items) | |
.where("EXTRACT(YEAR FROM items.sold_at)=:year", year: year) | |
.group("users.id") | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment