Last active
December 17, 2015 13:10
-
-
Save pierre/5615327 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
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