I have one MySQL query that shows total users grouped by countries (t1).
I have another MySQL query which shows countries that only has inactive users (t2).
Now, I want to have a resulting table that shows all the countries, total # users in those countries, followed by # inactive users in those countries (zero if there are no inactive users in those countries).
total users = active users + inactive users
This is the code so far:
with t1 as
(
Select country, count(users.id) AS 'total_users'
from users
group by country
),
t2 as
(
Select country, count(users.id) AS 'inactive_users'
From users left join orders on users.id = orders.user_id
Where orders.created_at is null
Group by Country)
How do I establish the resulting table ?
2
Answers