views:

57

answers:

1

Simplistically I have a table that looks like this:

ColA | ColB |
-----+------+
EE34 | Woo  |
ER56 | fro  |
EE34 | eco  |
QW34 | Sddg |
EE34 | zoo  |
ER56 | safe |

I need a select statement for SQL Server that produces:

ColA | Count |
-----+-------+
EE34 | 3     |
ER56 | 2     |
QW34 | 1     |

This could be running over a table with 100k+ records.

+4  A: 
SELECT  ColA, COUNT(*)
FROM    mytable
GROUP BY
        ColA

Or I am missing something?

Quassnoi
Nope, you're not missing anything..Altghough you could use something like this:SELECT Cola, COUNT(ColA) as Count FROM mytable GROUP BY ColANow you know for sure that cola gets counted and not just al rows.
Bloeper
`@Bloeper`: the results will only differ for the `NULL` values of `ColA` (the count will return `0` instead of actual number of `NULL` values)
Quassnoi