Skip to content

Instantly share code, notes, and snippets.

@eriktaubeneck
Last active January 23, 2018 15:42
Show Gist options
  • Save eriktaubeneck/0b446dde290cf50d9476d72ae08f8896 to your computer and use it in GitHub Desktop.
Save eriktaubeneck/0b446dde290cf50d9476d72ae08f8896 to your computer and use it in GitHub Desktop.
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