Created
January 2, 2018 14:24
-
-
Save daniel-sim/f0a960216ba87d50795d44462e897e2d to your computer and use it in GitHub Desktop.
This file contains 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
-- churned subscribers by month (only if they've paid once) | |
select thismonth.first_date as from_date, | |
thismonth.first_date + INTERVAL '1 month' as to_date, | |
count(*) as churned | |
from month thismonth | |
join app_history cancelled | |
on cancelled.event = 'Recurring charge cancelled' | |
and cancelled.date >= thismonth.first_date | |
and cancelled.date < thismonth.first_date + INTERVAL '1 month' | |
where exists (select 1 from app_history activated | |
where activated.event = 'Recurring charge activated' | |
and activated.shop_domain = cancelled.shop_domain | |
and coalesce(activated.billing_on,activated.date) <= cancelled.date | |
) | |
group by thismonth.first_date, thismonth.first_date + INTERVAL '1 month' | |
order by thismonth.first_date |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment