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.
| Author |
Topic |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2008-02-26 : 03:55:47
|
| Gender (TableName)Gen (ColoumnName)M(male)MF(female)MFFMFMNow, I have to retrieve the count of Male and Female. The Output should beMale 5Female 4Any one Help me plzzSuresh Kumar |
|
|
RickD
Slow But Sure Yak Herding Master
3608 Posts |
Posted - 2008-02-26 : 04:01:14
|
| Look up COUNT and GROUP BY in Book Online. |
 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2008-02-26 : 04:03:24
|
| select case when Gen='m' then 'Male'else 'Female'endas Gender,count(*)from Gendergroup byGen |
 |
|
|
sunil
Constraint Violating Yak Guru
282 Posts |
Posted - 2008-02-26 : 04:04:49
|
| declare @Gender table( gen varchar(10))Insert @Gender select 'M' union allselect 'M' union allselect 'F' union allselect 'M' union allselect 'M' union allselect 'F' union allselect 'M' union allselect 'M' Select 'Female' ,count(GEN) from @Gender group by gen having gen='F'union allSelect 'Male', count(GEN) from @Gender group by gen having gen='M' |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-02-26 : 04:23:35
|
| [code]SELECT 'Male '+CAST(SUM(CASE WHEN Gen='M' THEN 1 ELSE 0 END) AS varchar(4)) + CHAR(13) +'Female '+ CAST(SUM(CASE WHEN Gen='F' THEN 1 ELSE 0 END) AS varchar(4))FROM Table[/code] |
 |
|
|
ratheeshknair
Posting Yak Master
129 Posts |
Posted - 2008-02-26 : 08:24:55
|
| SELECT MALE,FEMALE FROM (SELECT COUNT(GEN) AS MALE FROM GENDER WHERE GEN = 'M') AS MALE,(SELECT COUNT(GEN) AS FEMALE FROM GENDER WHERE GEN = 'F') AS FEMALERKNAIR |
 |
|
|
|
|
|