Updated logic of model
This commit is contained in:
parent
b063454409
commit
261c6d3c49
2 changed files with 21 additions and 10 deletions
|
|
@ -7,7 +7,7 @@ with
|
|||
),
|
||||
monthly_revenue_per_number_of_properties as (
|
||||
select
|
||||
date_trunc('month', m.date)::date as metric_month,
|
||||
m.date as metric_month,
|
||||
coalesce(
|
||||
d.main_billing_country_iso_3_per_deal, 'global'
|
||||
) as main_billing_country_iso_3,
|
||||
|
|
@ -22,19 +22,20 @@ with
|
|||
on m.id_deal = d.id_deal
|
||||
and date_trunc('month', m.date) >= d.effective_deal_start_month
|
||||
and date_trunc('month', m.date)
|
||||
<= coalesce(d.effective_deal_cancellation_month, '2099-01-01')
|
||||
<= coalesce(d.hubspot_deal_cancellation_month, '2099-01-01')
|
||||
and date_trunc('month', m.date)::date <> date_trunc('month', now())::date
|
||||
where d.hubspot_listing_segmentation <> 'UNSET'
|
||||
group by
|
||||
rollup (
|
||||
date_trunc('month', m.date)::date,
|
||||
m.date,
|
||||
d.hubspot_listing_segmentation,
|
||||
d.main_billing_country_iso_3_per_deal
|
||||
)
|
||||
having date_trunc('month', m.date)::date is not null
|
||||
-- Exclude total date aggregation
|
||||
having m.date is not null
|
||||
)
|
||||
select
|
||||
(r.metric_month - interval '1 day')::date as date,
|
||||
r.metric_month as date,
|
||||
r.main_billing_country_iso_3,
|
||||
r.hubspot_listing_segmentation,
|
||||
sum(coalesce(m.total_revenue_in_gbp, 0)) as total_revenue_in_gbp,
|
||||
|
|
@ -44,8 +45,8 @@ select
|
|||
from monthly_revenue_per_number_of_properties m
|
||||
inner join
|
||||
monthly_revenue_per_number_of_properties r
|
||||
on r.metric_month > m.metric_month
|
||||
and r.metric_month <= m.metric_month + interval '12 months'
|
||||
on r.metric_month >= m.metric_month
|
||||
and r.metric_month < m.metric_month + interval '12 months'
|
||||
and r.hubspot_listing_segmentation = m.hubspot_listing_segmentation
|
||||
and r.main_billing_country_iso_3 = m.main_billing_country_iso_3
|
||||
group by r.metric_month, r.hubspot_listing_segmentation, r.main_billing_country_iso_3
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue