Skip to content
Advertisement

SQL count and group only returns first row for each group

My table:

This is what I’m trying to get

This is what I’m getting:

My code:

I’m getting the correct order with all the outpounts when i use ORDER BY and not GROUP/COUNT, but then I’m not getting the count. Don’t understand why I’m only getting the first row for each date.

Advertisement

Answer

If you want to add a column with the count to each row, use window functions:

If you want an aggregated list, then I’ll assume you are using MySQL (an old version) or SQLite because these do not generate a syntax error. In that case, you can use group_concat():

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement