Created
September 2, 2015 17:51
-
-
Save brachycera/44c13f59e947ca579ae8 to your computer and use it in GitHub Desktop.
Multiple count within one query
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
SELECT | |
SUM(CASE WHEN foo = '0' THEN 1 ELSE 0 END) AS bar_count, | |
SUM(CASE WHEN foo = '1' OR foo = '2' THEN 1 ELSE 0 END) AS baz_count | |
FROM | |
database | |
WHERE | |
baz = qux | |
GROUP BY baz |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment