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
 Simple SELECT Query

Author  Topic 

SuperSQLNewb
Starting Member

9 Posts

Posted - 2009-04-23 : 11:58:33
Hi guys,

I have a table like this:
ID Status
1 New
2 Old
3 Can
4 New
5 New
6 Old

And I want the output of my query to be like this:

Status Count
New 3
Old 2
Can 1

I just want to display all of the various status values in the table and a count for how many each one has.

How can I do this? I assume I need to use DISTINCT, COUNT and GROUP BY somehow but I can't seem to make it work.

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-04-23 : 12:01:16
select Status, Count(*) as [Count] from table group by Status


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

SuperSQLNewb
Starting Member

9 Posts

Posted - 2009-04-23 : 12:10:57
Thanks! You Yak'n'Roll
Go to Top of Page
   

- Advertisement -