Created
April 6, 2016 15:39
-
-
Save jthandy/5e1913fa12d351b42f3310f91c9db6cc to your computer and use it in GitHub Desktop.
This file contains 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
customers as ( | |
select customer, min(period_start) as active_from, max(period_end) as active_to | |
from invoices | |
where period_start <= current_date | |
group by customer | |
), customer_dates as ( | |
select m.date_month, c.customer | |
from months m | |
inner join customers c | |
on m.date_month >= date_trunc('month', c.active_from) | |
and m.date_month < date_trunc('month', c.active_to) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment