Skip to content

Instantly share code, notes, and snippets.

@workmad3
Created July 22, 2010 07:32
Show Gist options
  • Select an option

  • Save workmad3/485696 to your computer and use it in GitHub Desktop.

Select an option

Save workmad3/485696 to your computer and use it in GitHub Desktop.
class Order < ActiveRecord::Base
named_scope :order_counts, lambda { |*args| {:joins => :customer,:select => 'COUNT(DISTINCT customer_id) customer_id,category_id,product_price,quantity, SUM(product_price * quantity) AS my_sum', :group => 'category_id', :conditions => ['orders.created_at <= ? AND customers.temp = ?',args[0], args[1]]}}
end
Order.order_counts.first.my_sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment