Created
April 6, 2016 19:09
-
-
Save jthandy/385a75de3e0a96a839d6989cb2a481e0 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
data as ( | |
select *, | |
case | |
when first_payment = 1 | |
then 'new' | |
when last_payment = 1 | |
and dateadd('month', 1, period_end) < current_date | |
then 'churn' | |
when change > 0 | |
then 'upgrade' | |
when change < 0 | |
then 'downgrade' | |
when period != 'monthly' | |
and date_month < date_trunc('month', prior_month_period_end) | |
then 'prepaid renewal' | |
else | |
'renewal' | |
end revenue_category, | |
case | |
when prior_month_total < total then prior_month_total | |
else total | |
end renewal_component_of_change | |
from plan_changes | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment