Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Multiple count within one query
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