I have found select statements that basically use different where clauses to count. My question is, how do I combine the results in one statement so that these counts can become columns?
SELECT
COUNT(CASE WHEN city = 'nyc' THEN 1 END) AS Nyc,
COUNT(CASE WHEN city = 'boston' THEN 1 END) AS Boston,
COUNT(CASE WHEN city = 'sf' THEN 1 END) AS Sf
FROM table
You can give GROUP BY a chance,
SELECT city, gender, count(*)
WHERE gender = "male"
GROUP BY city, gender;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With