Skip to content

Instantly share code, notes, and snippets.

@jthandy
Created April 6, 2016 19:06
Show Gist options
  • Save jthandy/0a33350c56dc386d41a0396bda18f068 to your computer and use it in GitHub Desktop.
Save jthandy/0a33350c56dc386d41a0396bda18f068 to your computer and use it in GitHub Desktop.
plan_changes as (
select
*,
lag(total) over (partition by customer order by date_month) as prior_month_total,
total - coalesce(lag(total) over (partition by customer order by date_month), 0) as change,
lag(period_end) over (partition by customer order by date_month) as prior_month_period_end
from invoices
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment