Hello List,
I submitted the code below, I want to count the percentage of male in a table. the data is not clean, the values of 1 and Male in column gender are Male. I use sum function to count total number in the column and use count() function to get the total number form the table. Both of function are work well. But when I counting the percentage by "SUM(CASE WHEN gender in ('Male', '1') THEN 1 ELSE 0 END) / count() as pct_male", the result is 0. based on my maunale count, the value should be ~ 0.5. can you help me?
Thanks,
select
SUM(CASE WHEN gender in ('Male', '1') THEN 1 ELSE 0 END) as N_male,
count() as overall,
SUM(CASE WHEN gender in ('Male', '1') THEN 1 ELSE 0 END) / count() as pct_male
from gemd.Respondents_tidy