Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Other Forums
 MS Access
 Counting rows from columns

Author  Topic 

anishap
Yak Posting Veteran

61 Posts

Posted - 2008-10-08 : 15:29:40
I have a table with the below data:

ID Cat Rat Rabbits

001 A B D
002 A C E
003 B A A
004 A E B
005 D A B
006 B C A

I want to count the # of A,B,C,D and E's from each column.

SELECT cat,sum(Abs(cat="A" or "B" or "C" or "D")) as Cat_Tot from sample group by cat.


The above query works for single column.

Output sample.
Cat Count Rat Count Rabbits Count
A 2 A 2 A 1
B 2 B 1 C 2

Can anyone help with this please?


   

- Advertisement -