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
 General SQL Server Forums
 New to SQL Server Programming
 COUNTING ELEMENTS IN COLUMN

Author  Topic 

DaveyB
Starting Member

10 Posts

Posted - 2008-06-28 : 16:41:44
Dear All,

I have a column like this

Alphabet_Letters
A
B
A
C
B
C
D
A
E

What I want to do is cound all the A's, B's and C's in there. How would I approach this task. I tried using a case statement but when I used the COUNT method it produced an error. Thanks!

maninder
Posting Yak Master

100 Posts

Posted - 2008-06-28 : 19:48:14
select distinct name,count(*) from column
Group by column

Maninder
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-29 : 02:25:44
quote:
Originally posted by maninder

select distinct name,count(*) from column
Group by column

Maninder


why do you need distinct here? i think this is enough

select Alphabet_Letters,count(*)
from Youratbel
group by Alphabet_Letters
Go to Top of Page

maninder
Posting Yak Master

100 Posts

Posted - 2008-06-29 : 11:34:46
u r correct.

Maninder
Go to Top of Page
   

- Advertisement -