Using group by on two fields and count in SQL
I think you're looking for: SELECT a, b, COUNT(a) FROM tbl GROUP BY a, b
SELECT group,subGroup,COUNT(*) FROM tablename GROUP BY group,subgroup
You must group both columns, group and sub-group, then use the aggregate function COUNT()
.
SELECT
group, subgroup, COUNT(*)
FROM
groups
GROUP BY
group, subgroup