views:

39

answers:

2

Hard to capture the problem in a single sentence, but the problem is a simple one. Table looks like this:

   col_a   col_b
   v1      c
   v2      c
   v3      c
   v5      d
   v2      d
   v1      a
   v5      a
   v7      a
   v4      a

Each row is distinct, and I need a count of the rows for each unique value of col_b. So, my result set for this table should be:

c   3
d   2
a   4

I have no idea how to think this thru and do it.

+2  A: 

I'm assuming that you're asking how to do this in SQL.

Use GROUP BY with an aggregate function, like this:

SELECT col_b, COUNT(*) FROM MyTable GROUP BY col_b
SLaks
You beat me to the punch. Dunno if this is supposed to be SQL or what, though.
peacedog
+1  A: 

Well, in SQL you would do:

SELECT col_b, COUNT(ol_a)
FROM SomeTable
GROUP BY col_b
peacedog