Having Problems With group_by syntax

I am embarrassed to say I am having problems with the group by syntax.

What I want to do is take a record set that is returned and group it by the updated_at field (but only up to the day and not hours, seconds, minutes, etc.). So that I can display a list broken up by day.

Can someone help me with the syntax?

I greatly appreciate it! :slight_smile:

I have a table that records when a task is completed. If I want to see how many tasks were completed on each day, I could do something like

select substring(completed, 1, 10) as completed, count(*)
from completed_tasks
group by substring(completed, 1, 10)
order by completed

That's PostgreSQL, and there is probably a more correct way of doing it, but that works. Just remember that any column in the select that is not an aggregate must be included in the group by. That's where it starts to get cumbersome.

Peace,
Phillip

I was referring to the Enumerable#group_by method... not the group by in mySQL... help someone please? :-)

I am almost their… now how can I make updated_at only go down to the day level? This solution will divide things up to the second instead of by day.

I really appreciate everyone’s help!

Hm. Well, sorry about that. I think my problem is I don't always go for the Rails purist way to solve things. At least not yet. That's twice today that I've answered with a SQL solution where I shouldn't have. *sigh* But, hey, if you ever find yourself writing some raw SQL, just keep in mind what I said. :wink:

Peace,
Phillip