Last active
January 23, 2018 15:42
-
-
Save eriktaubeneck/0b446dde290cf50d9476d72ae08f8896 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
select m.month, coalesce(s.signup_count, 0), coalesce(p.purchase_count, 0) | |
from ( | |
select extract(month from ts) as month | |
from signups | |
union all | |
select extract(month from ts) as month | |
from purchases | |
group by month | |
) as m | |
left outer join ( | |
select extract(month from ts) as month, count(user_id) as signup_count | |
from signups | |
group by extract(month from ts) | |
) s | |
on m.month = s.month | |
left outer join ( | |
select extract(month from ts) as month, count(purchase_id) as purchase_count | |
from purchases | |
where product_id not in (2342, 8980) | |
group by extract(month from ts) | |
) p | |
on m.month = p.month; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment