Skip to content

Instantly share code, notes, and snippets.

@petdance
Last active May 3, 2019 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save petdance/c17c148ce06c72a5324256f6e14c6c3f to your computer and use it in GitHub Desktop.
Save petdance/c17c148ce06c72a5324256f6e14c6c3f to your computer and use it in GitHub Desktop.
Gender counts per reason
/* The MariaDB I installed doesn't support CTEs, so use a subquery */
SELECT * FROM (
select
reason,
SUM( CASE WHEN gender = 'Male' THEN 1 END) as M,
SUM( CASE WHEN gender = 'Female' THEN 1 END) as F,
SUM( CASE WHEN gender NOT IN ('Male','Female') THEN 1 END) AS X,
COUNT(gender) AS T
from response
inner join reasons on reasons.responseid = response.responseid
group by reason
) stats
order by T desc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment