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)
 count of all the columns with condition imposed on

Author  Topic 

itsrahulk
Starting Member

2 Posts

Posted - 2010-04-16 : 04:51:37
hi.

i have a table below

msisdn zmu retailer cif_status
9895999 ewew3443 4343434 Y
434434 43434343 34343 N
334343 4334343 4344344 Y
323232 343434 43434343 N

i need count of all msisdn, count of all zmu and count of cif_status who have 'N' only

please help me how could i solve

as when i impoese condition in my query for cif_status ='N'
it gives me count of only 'N' records.

i need all the count of msisdn, zmu but count of cif_status who has 'N'

Thanks

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-16 : 04:54:46
count(case when cif_status='N' then 1 else 0 end) as count_of_cif_status_N


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

Bustaz Kool
Master Smack Fu Yak Hacker

1834 Posts

Posted - 2010-04-16 : 18:23:45
SUM(case when cif_status='N' then 1 else 0 end) as count_of_cif_status_N


=======================================
A couple of months in the laboratory can save a couple of hours in the library. -Frank H. Westheimer, chemistry professor (1912-2007)
Go to Top of Page
   

- Advertisement -