diff options
author | Akira Matsuda <ronnie@dio.jp> | 2011-06-29 08:04:11 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2011-06-29 08:09:02 +0900 |
commit | cfab51c819111d1dff3e6094e49ed33bc9262305 (patch) | |
tree | e965c9601151e810f418c1ca7f9030aa0102884d /railties/guides | |
parent | 6a1803a14f069d7bd0138510129693874bd84938 (diff) | |
download | rails-cfab51c819111d1dff3e6094e49ed33bc9262305.tar.gz rails-cfab51c819111d1dff3e6094e49ed33bc9262305.tar.bz2 rails-cfab51c819111d1dff3e6094e49ed33bc9262305.zip |
correct invalid GROUP BY query
GROUP BY value must appear in SELECT clause
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_record_querying.textile | 4 |
1 files 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: <ruby> -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)") </ruby> 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: <sql> -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) </sql> h3. Having |