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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Simple query

Author  Topic 

mauler05
Starting Member

17 Posts

Posted - 2007-12-12 : 14:35:52
Query :

select sum(case Gender when 'M' then 1 else 0 end) AS Male,
sum(case Gender when 'F' then 1 else 0 end) AS Female,
sum(case Gender when 'U' then 1 else 0 end) AS Unknown
from User

Output :

Male Female Unknown
10 20 30

How to get the following output

Male 10
Female 20
Unknown 30



Thanks in advance !!

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-12-12 : 14:39:24
SELECT Gender, COUNT(Gender)
FROM YourTable
GROUP BY Gender

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

mauler05
Starting Member

17 Posts

Posted - 2007-12-12 : 15:07:30
Thanks.
Go to Top of Page
   

- Advertisement -