From cfab51c819111d1dff3e6094e49ed33bc9262305 Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 29 Jun 2011 08:04:11 +0900 Subject: correct invalid GROUP BY query GROUP BY value must appear in SELECT clause --- railties/guides/source/active_record_querying.textile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/railties/guides/source/active_record_querying.textile b/railties/guides/source/active_record_querying.textile index 1c5f5ada4a..93a98755a2 100644 --- a/railties/guides/source/active_record_querying.textile +++ b/railties/guides/source/active_record_querying.textile @@ -466,7 +466,7 @@ To apply a +GROUP BY+ clause to the SQL fired by the finder, you can specify the For example, if you want to find a collection of the dates orders were created on: -Order.group("date(created_at)").order("created_at") +Order.select("date(created_at) as ordered_date, sum(price) as total_price").group("date(created_at)") And this will give you a single +Order+ object for each date where there are orders in the database. @@ -474,7 +474,7 @@ And this will give you a single +Order+ object for each date where there are ord The SQL that would be executed would be something like this: -SELECT * FROM orders GROUP BY date(created_at) ORDER BY created_at +SELECT date(created_at) as ordered_date, sum(price) as total_price FROM orders GROUP BY date(created_at) h3. Having -- cgit v1.2.3