Skip to content

Instantly share code, notes, and snippets.

@pierre
Last active December 17, 2015 13:10
Show Gist options
  • Save pierre/5615327 to your computer and use it in GitHub Desktop.
Save pierre/5615327 to your computer and use it in GitHub Desktop.
select
effective_date
, cur_period_rev.recognized_amount + past_period_rev.recognized_amount
from (
select distinct effective_date fulldate from recognized_revenue
) pivot_date
join (
select
effective_date
, recognized_amount
from recognized_revenue
) cur_period_rev on recognized_date = date_format(pivot_date.fulldate, '%Y-%m-01') and effective_date = pivot_date.fulldate
join (
select
recognized_date
, sum(recognized_amount) recognized_amount
from recognized_revenue
where effective_date = last_day(effective_date)
group by 1
) past_period_rev on recognized_date = date_format(pivot_date.fulldate, '%Y-%m-01')
;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment