To use a GROUP BY clause to the SQL fired by the finder, you can specify the group method on the find query.
For example, if you want to find a collection of dates the Orders were created on:
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.
The sql query for this will be :
SELECT date(created_at) as ordered_date, sum(price) as total_price
FROM orders
GROUP BY date(created_at)
0 Comment(s)