Im trying to count the number of males, the number of females and then the number of people who havent specified either, i.e people will NULL in the gnder field. I need to table to appear like this
have you tried using something like union selects :
select u.male, u.female from (count(field) as male where field = "male" Union select count(field) as female where = "female"...) as u
(note this wont actually run, but its a start)
select gender, count(gender)
from table
where gender = 'Male'
union all
select gender, count(gender)
from table
where gender = 'Female'
union all
select 'None Specified', count(gender)
from table
where gender <> 'Male'
and gender <> 'Female'
select gender =
case gender
when 'm' then 'Male'
when 'f' then 'Female'
else 'None Specified' end, count(*) cnt from table group by gender order by cnt
select gender =
case gender
when 'male' then 'Male'
when 'female' then 'Female'
else 'None Specified' end, count(*) cnt from table group by gender order by cnt
Not sure how the gender field is displayed in your table
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.