Skip to content

Instantly share code, notes, and snippets.

@jthandy
Created April 6, 2016 19:09
Show Gist options
  • Save jthandy/385a75de3e0a96a839d6989cb2a481e0 to your computer and use it in GitHub Desktop.
Save jthandy/385a75de3e0a96a839d6989cb2a481e0 to your computer and use it in GitHub Desktop.
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