Skip to content
Advertisement

Using group by on two fields and count in SQL

I have a table in my mysql db that has two columns: group and subgroup. See below.

I am trying to get the number of records for each unique couple group/subGroup.

This is what I expect:

After reading some posts I tried several sql queries using group by, count(), but I do not manage to get the expected result. How can I fix this?

Advertisement

Answer

I think you’re looking for: SELECT a, b, COUNT(a) FROM tbl GROUP BY a, b

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