Skip to content
This repository
Browse code

correct invalid GROUP BY query

GROUP BY value must appear in SELECT clause
  • Loading branch information...
commit cfab51c819111d1dff3e6094e49ed33bc9262305 1 parent 6a1803a
Akira Matsuda amatsuda authored

Showing 1 changed file with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. +2 2 railties/guides/source/active_record_querying.textile
4 railties/guides/source/active_record_querying.textile
Source Rendered
@@ -466,7 +466,7 @@ To apply a +GROUP BY+ clause to the SQL fired by the finder, you can specify the
466 466 For example, if you want to find a collection of the dates orders were created on:
467 467
468 468 <ruby>
469   -Order.group("date(created_at)").order("created_at")
  469 +Order.select("date(created_at) as ordered_date, sum(price) as total_price").group("date(created_at)")
470 470 </ruby>
471 471
472 472 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
474 474 The SQL that would be executed would be something like this:
475 475
476 476 <sql>
477   -SELECT * FROM orders GROUP BY date(created_at) ORDER BY created_at
  477 +SELECT date(created_at) as ordered_date, sum(price) as total_price FROM orders GROUP BY date(created_at)
478 478 </sql>
479 479
480 480 h3. Having

0 comments on commit cfab51c

Please sign in to comment.
Something went wrong with that request. Please try again.