-
-
Save AshleyPinner/ffef5fdd9e8e3fbd3c9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* basic testcase: */ | |
create table `stats` ( | |
`id` int(11) NOT NULL AUTO_INCREMENT, | |
`gender` char(1) DEFAULT 'U', | |
PRIMARY KEY (`id`) | |
); | |
insert into `stats` (gender) values ('M'), ('F'), ('U'), ('M'), ('F'), ('U'), (''), (''), (null), (null); | |
/* simplified query */ | |
SELECT | |
CASE gender WHEN 'M' THEN "Male" WHEN 'F' THEN "Female" ELSE 'Unknown' END AS gender, | |
count(gender) as `count` | |
FROM stats | |
/*WHERE 1 = 1*/ | |
group by gender | |
order by gender; | |
/* Sample output: | |
Female 2 | |
Male 2 | |
Unknown 2 | |
Unknown 2 | |
Unknown 0 */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment