Monday, 9 September 2013

MySQL count on Grouping

MySQL count on Grouping

I want to count the number of times a grouping occurs in a query.
SELECT COL1,
COL2,
*(count COL1)*
FROM TABLE
GROUP BY COL1, COL2
So I'm expecting to see the results like so:
COL1, COL2, Count
A, A, 1
A, B, 2
B, A, 1
B, B, 2
B, C, 3
Count(*) will give me the sum of the grouped row which is what I don't
want, but I just cant seem to get my head round it or find a way to do it.
Anyway, thanks in advance.

No comments:

Post a Comment