how do you get the sql output as below?

Use conditional aggregation. In standard SQL:

select 
    sum(case when gender = 'M' then 1 else 0 end) male,
    sum(case when gender = 'F' then 1 else 0 end) female
from mytable

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top