📘Introducing SQL Notebooks: Tell stories using data.Read more →

How to Have Multiple Counts in MySQL

To do multiple counts in one query in MySQL, you can combine COUNT() with IF():

  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;

Ready for a modern SQL editor?