The ActiveRecord group method will do what you need. In your case, the problem would be to use created_at , which is a date-time, and your restriction for grouping by date. Because date-time dates for dates are database dependent, the code must also be database specific.
For MySql you can:
Model.group("date(table_name.created_at)")
For SQLite, you can:
Model.group("strftime('%Y-%m-%d', table_name.created_at)")
And for PostgreSQL:
Model.group("table_name.created_at::date")
This code, unfortunately, will not be portable, but it may not matter to you. If so, you can always create a shell method that selects the correct conversion syntax based on your DBMS.
source share