Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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")
.where("EXTRACT(YEAR FROM items.sold_at)=:year", year: year)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.