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)
 How can i get count for this

Author  Topic 

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-07-17 : 03:35:14
The data in my table is as follows

FirstName Gender
AABHA F
AABHA F
AABHA NULL
AABHA M
Satish M
Satish NULL
Satish U

Output need like this
FirstName Cnt
AABHA 3
Satish 2

Here requirement is i need to count the First_names if Gender is "F" or "NULL". For example for name "AABAH", total 4 rows are there. But i need only count considering gender as "F" and "NULL". So count appears as 3 in output.

I tried this query but getting wrong results.

Select FirstName, Count(Gender) as SexCnt from StandardVoter Where FirstName = 'AABHA'
Group by Gender having Gender is NULL or Gender = 'F'


G. Satish

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-17 : 03:36:34
[code]
select FirstName, count(Gender)
from table
group by FirstName
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

satish.gorijala
Posting Yak Master

182 Posts

Posted - 2009-07-17 : 03:41:19
Here requirement is i need to count the First_names if Gender is "F" or "NULL". For example for name "AABAH", total 4 rows are there. But i need only count considering gender as "F" and "NULL". So count appears as 3 in output.

quote:
Originally posted by khtan


select FirstName, count(Gender)
from table
group by FirstName



KH
[spoiler]Time is always against us[/spoiler]





G. Satish
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2009-07-17 : 03:49:59
[code]
select FirstName, count(*)
from table
where Gender is null or Gender = 'F'
group by FirstName
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -