Answer the question
In order to leave comments, you need to log in
How to write sql correctly?
SELECT countries.short_name, COUNT(user.id), COUNT(user.id WHERE user.status = 1) FROM user INNER JOIN countries ON user.country_id = countries.country_id
GROUP BY short_name
Answer the question
In order to leave comments, you need to log in
If you need a COUNT with a WHERE, that's not how it's done.
See HAVING
SELECT
countries.short_name,
COUNT(user.id) as cnt_all_stat_user,
COALESCE(sum(case when user.status = 1 then 1 end),0) as cnt_stat_1_user
FROM user
INNER JOIN countries
ON user.country_id = countries.country_id
GROUP BY short_name
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question