How to Have Multiple Counts in MySQL
To do multiple counts in one query in MySQL, you can combine COUNT()
with IF()
:
SELECT
COUNT(1), -- Count all users
COUNT(IF(gender='male', 1, 0)), -- Count male users
COUNT(IF(beta=true, 1, 0)) -- Count beta users
COUNT(IF(active=true AND beta = false, 1, 0)) -- Count active non-beta users
FROM users;
From MySQL query to chart to Slack in seconds
Get to answers faster, together, with PopSQL and MySQL