Eben. Du benutzt kein GROUP BY. Um SUM zu nutzen musst du das aber, da ja sonst nicht klar in welchem 'scope' hier aufsummiert werden soll.
Wie waere es damit? :group => :products g phil On Sat, Nov 07, 2009 at 11:50:36AM +0100, rubyonrails...@galt.de wrote: > Hallo, > > das Teil bringt mich zur Verzweiflung(Rails 2.3.4): > > Product.count( > :conditions => [ > 'SUM(po_items.quantity) > SUM(sales.quantity)' > ], > :include => [:po_items, :sales] > ) > > Die Assoziation ist so angelegt, daß jedes Produkt mehrere Bestellungen > und mehrere Sales haben kann. > > Alles, was ich haben möchte, ist die Liste aller Produkte bei denen die > Anzahl der bestellten Exemplare größer ist als die Anzahl der verkauften > Exemplare. > > MySql haut mir aber jedes mal diese Fehlermeldung um die Ohren: > > ActiveRecord::StatementInvalid: Mysql::Error: Invalid use of group > function: SELECT count(DISTINCT `products`.id) AS count_all FROM > `products` LEFT OUTER JOIN `po_items` ON po_items.product_id = > products.id LEFT OUTER JOIN `sales` ON sales.product_id = products.id > WHERE (SUM(po_items.quantity) > SUM(sales.quantity)) > > Ich verwende aber gar kein GROUP BY! > > Weiß vielleicht jemand, was das Problem ist? > > Viele Grüße > > Michael Kastner > _______________________________________________ > rubyonrails-ug mailing list > rubyonrails-ug@headflash.com > http://mailman.headflash.com/listinfo/rubyonrails-ug _______________________________________________ rubyonrails-ug mailing list rubyonrails-ug@headflash.com http://mailman.headflash.com/listinfo/rubyonrails-ug