i have table like this
sno name dno gender idno
1 shashi 5-4 male 123
2 roja 6-4 female 123
3 raju 7-4 male 134
4 pravalika 8-9 female 134
5 vamshi 9-2 male 123
i want count male and female group by idno
i wnat output like this
idno male female
123 2 1
134 1 1
Select count distinct id
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 23, 2013, 9:27 PM EST
SUM(CASE WHEN gender = 'male' THEN 1 ELSE 0 END) as MaleCount,
SUM(CASE WHEN gender = 'female' THEN 1 ELSE 0 END) as FemaleCount,
idno
FROM tab3 group by idno
Milstein MunakamiRank #2,283 · 617 reputationPosted Nov 23, 2013, 9:39 PM EST
Solution:
Jignesh TrivediRank #16 · 50.3K reputationPosted Nov 24, 2013, 7:37 PM EST
try...
select idno,sum(male) as Male,sum(female) as Female from #temp
pivot (COUNT(gender) for gender in ([male], [female])) as p
group by idno