fixed int_monthly_growth_score_by_deal
This commit is contained in:
parent
5bcfd7cb9c
commit
abd4a4e8f2
1 changed files with 29 additions and 29 deletions
|
|
@ -71,7 +71,7 @@ with
|
|||
coalesce(sum(previous_twelve_months.revenue_in_gbp), 0), 0
|
||||
) as effective_deal_revenue_12_months_window
|
||||
from deal_history_from_previous_months as given_month
|
||||
-- Retrieve agg data from same deal from the previous twelve
|
||||
-- Retrieve aggregated data from same deal from the previous twelve
|
||||
-- months
|
||||
left join
|
||||
deal_history_from_previous_months as previous_twelve_months
|
||||
|
|
@ -81,7 +81,7 @@ with
|
|||
and given_month.first_day_month
|
||||
>= previous_twelve_months.first_day_month + interval '1 months'
|
||||
group by 1, 2
|
||||
) as agg_revenue_data_before_partition
|
||||
) as aggregated_revenue_data_before_partition
|
||||
),
|
||||
metrics_attribution_to_given_month_per_deal as (
|
||||
select
|
||||
|
|
@ -100,10 +100,10 @@ with
|
|||
previous_2_month.first_day_month as previous_2_month_first_day_month,
|
||||
previous_12_month.first_day_month as previous_12_month_first_day_month,
|
||||
previous_13_month.first_day_month as previous_13_month_first_day_month,
|
||||
agg_12m_window.from_first_day_month
|
||||
as agg_revenue_from_first_day_month,
|
||||
agg_12m_window.to_first_day_month
|
||||
as agg_revenue_to_first_day_month,
|
||||
aggregated_12m_window.from_first_day_month
|
||||
as aggregated_revenue_from_first_day_month,
|
||||
aggregated_12m_window.to_first_day_month
|
||||
as aggregated_revenue_to_first_day_month,
|
||||
|
||||
-- Revenue --
|
||||
given_month.revenue_in_gbp as given_month_revenue_in_gbp,
|
||||
|
|
@ -154,54 +154,54 @@ with
|
|||
|
||||
-- 12 Months Window (Account Size) --
|
||||
-- Bookings --
|
||||
agg_12m_window.deal_created_bookings_12_months_window,
|
||||
agg_12m_window.global_created_bookings_12_months_window,
|
||||
aggregated_12m_window.deal_created_bookings_12_months_window,
|
||||
aggregated_12m_window.global_created_bookings_12_months_window,
|
||||
coalesce(
|
||||
cast(
|
||||
agg_12m_window.deal_created_bookings_12_months_window
|
||||
aggregated_12m_window.deal_created_bookings_12_months_window
|
||||
as decimal
|
||||
) / nullif(
|
||||
agg_12m_window.global_created_bookings_12_months_window, 0
|
||||
aggregated_12m_window.global_created_bookings_12_months_window, 0
|
||||
),
|
||||
0
|
||||
) as deal_contribution_share_to_global_created_bookings,
|
||||
agg_12m_window.deal_contribution_rank_to_global_created_bookings,
|
||||
aggregated_12m_window.deal_contribution_rank_to_global_created_bookings,
|
||||
|
||||
-- Listings --
|
||||
round(
|
||||
agg_12m_window.deal_avg_listings_booked_in_month_12_months_window,
|
||||
aggregated_12m_window.deal_avg_listings_booked_in_month_12_months_window,
|
||||
2
|
||||
) as deal_avg_listings_booked_in_month_12_months_window,
|
||||
round(
|
||||
agg_12m_window.global_avg_listings_booked_in_month_12_months_window,
|
||||
aggregated_12m_window.global_avg_listings_booked_in_month_12_months_window,
|
||||
2
|
||||
) as global_avg_listings_booked_in_month_12_months_window,
|
||||
coalesce(
|
||||
cast(
|
||||
agg_12m_window.deal_avg_listings_booked_in_month_12_months_window
|
||||
aggregated_12m_window.deal_avg_listings_booked_in_month_12_months_window
|
||||
as decimal
|
||||
) / nullif(
|
||||
agg_12m_window.global_avg_listings_booked_in_month_12_months_window,
|
||||
aggregated_12m_window.global_avg_listings_booked_in_month_12_months_window,
|
||||
0
|
||||
),
|
||||
0
|
||||
) as deal_contribution_share_to_global_avg_listings_booked_in_month,
|
||||
agg_12m_window.deal_contribution_rank_to_global_avg_listings_booked_in_month,
|
||||
aggregated_12m_window.deal_contribution_rank_to_global_avg_listings_booked_in_month,
|
||||
|
||||
-- Revenue --
|
||||
agg_12m_window.deal_revenue_12_months_window,
|
||||
agg_12m_window.effective_deal_revenue_12_months_window,
|
||||
agg_12m_window.effective_global_revenue_12_months_window,
|
||||
aggregated_12m_window.deal_revenue_12_months_window,
|
||||
aggregated_12m_window.effective_deal_revenue_12_months_window,
|
||||
aggregated_12m_window.effective_global_revenue_12_months_window,
|
||||
coalesce(
|
||||
cast(
|
||||
agg_12m_window.effective_deal_revenue_12_months_window
|
||||
aggregated_12m_window.effective_deal_revenue_12_months_window
|
||||
as decimal
|
||||
) / nullif(
|
||||
agg_12m_window.effective_global_revenue_12_months_window, 0
|
||||
aggregated_12m_window.effective_global_revenue_12_months_window, 0
|
||||
),
|
||||
0
|
||||
) as deal_contribution_share_to_global_revenue,
|
||||
agg_12m_window.deal_contribution_rank_to_global_revenue
|
||||
aggregated_12m_window.deal_contribution_rank_to_global_revenue
|
||||
|
||||
from deal_history_from_previous_months as given_month
|
||||
-- Retrieve monthly data from same deal and previous month
|
||||
|
|
@ -232,9 +232,9 @@ with
|
|||
and previous_13_month.id_deal = given_month.id_deal
|
||||
-- Retrieve aggregation over 12 previous months
|
||||
left join
|
||||
revenue_12_months_window_aggregation_per_deal agg_12m_window
|
||||
on agg_12m_window.id_deal = given_month.id_deal
|
||||
and agg_12m_window.first_day_month = given_month.first_day_month
|
||||
revenue_12_months_window_aggregation_per_deal aggregated_12m_window
|
||||
on aggregated_12m_window.id_deal = given_month.id_deal
|
||||
and aggregated_12m_window.first_day_month = given_month.first_day_month
|
||||
),
|
||||
growth_score_computation as (
|
||||
select
|
||||
|
|
@ -250,8 +250,8 @@ with
|
|||
m.previous_2_month_first_day_month,
|
||||
m.previous_12_month_first_day_month,
|
||||
m.previous_13_month_first_day_month,
|
||||
m.agg_revenue_from_first_day_month,
|
||||
m.agg_revenue_to_first_day_month,
|
||||
m.aggregated_revenue_from_first_day_month,
|
||||
m.aggregated_revenue_to_first_day_month,
|
||||
|
||||
m.given_month_revenue_in_gbp,
|
||||
m.previous_1_month_revenue_in_gbp,
|
||||
|
|
@ -358,8 +358,8 @@ select
|
|||
gsc.previous_2_month_first_day_month,
|
||||
gsc.previous_12_month_first_day_month,
|
||||
gsc.previous_13_month_first_day_month,
|
||||
gsc.agg_revenue_from_first_day_month,
|
||||
gsc.agg_revenue_to_first_day_month,
|
||||
gsc.aggregated_revenue_from_first_day_month,
|
||||
gsc.aggregated_revenue_to_first_day_month,
|
||||
|
||||
gsc.given_month_revenue_in_gbp,
|
||||
gsc.previous_1_month_revenue_in_gbp,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue