Update
This commit is contained in:
parent
26898322e7
commit
c0da375223
1 changed files with 18 additions and 8 deletions
|
|
@ -28,15 +28,27 @@ with
|
||||||
booked_days_per_deal as (
|
booked_days_per_deal as (
|
||||||
select
|
select
|
||||||
icuh.id_deal,
|
icuh.id_deal,
|
||||||
hd.live_date_utc as created_date_utc,
|
icb.created_date_utc as created_date_utc,
|
||||||
lag(hd.live_date_utc, 1) over (
|
lag(icb.created_date_utc, 1) over (
|
||||||
partition by icuh.id_deal order by hd.live_date_utc asc
|
partition by icuh.id_deal order by icb.created_date_utc asc
|
||||||
) as previous_booked_date
|
) as previous_booked_date
|
||||||
from int_core__bookings icb
|
from int_core__bookings icb
|
||||||
inner join int_core__user_host icuh on icb.id_user_host = icuh.id_user_host
|
inner join int_core__user_host icuh on icb.id_user_host = icuh.id_user_host
|
||||||
inner join int_hubspot__deal hd on icuh.id_deal = hd.id_deal
|
inner join int_hubspot__deal hd on icuh.id_deal = hd.id_deal
|
||||||
where icuh.id_deal is not null
|
where icuh.id_deal is not null
|
||||||
group by icuh.id_deal, hd.live_date_utc
|
group by icuh.id_deal, icb.created_date_utc
|
||||||
|
),
|
||||||
|
deals as (
|
||||||
|
select
|
||||||
|
coalesce(hd.id_deal, h.id_deal) as id_deal,
|
||||||
|
min(coalesce(hd.live_date_utc, h.created_date_utc)) as created_date_utc
|
||||||
|
from intermediate.int_hubspot__deal hd
|
||||||
|
full outer join
|
||||||
|
intermediate.int_core__user_host h
|
||||||
|
on hd.id_deal = h.id_deal
|
||||||
|
and h.id_deal is not null
|
||||||
|
where hd.id_deal is not null
|
||||||
|
group by 1
|
||||||
),
|
),
|
||||||
deal_historic_booking_dates as (
|
deal_historic_booking_dates as (
|
||||||
select
|
select
|
||||||
|
|
@ -47,7 +59,7 @@ with
|
||||||
max(b.created_date_utc) as last_time_booked_date_utc,
|
max(b.created_date_utc) as last_time_booked_date_utc,
|
||||||
max(b.previous_booked_date) as second_to_last_time_booked_date_utc
|
max(b.previous_booked_date) as second_to_last_time_booked_date_utc
|
||||||
from int_kpis__dimension_dates d
|
from int_kpis__dimension_dates d
|
||||||
inner join int_core__user_host h on d.date >= h.created_date_utc
|
inner join deals h on d.date >= h.created_date_utc
|
||||||
left join
|
left join
|
||||||
booked_days_per_deal b
|
booked_days_per_deal b
|
||||||
on h.id_deal = b.id_deal
|
on h.id_deal = b.id_deal
|
||||||
|
|
@ -145,9 +157,7 @@ select
|
||||||
case
|
case
|
||||||
-- 01-New: The deal has been created this month.
|
-- 01-New: The deal has been created this month.
|
||||||
-- Additionally, the deal has not been offboarded in hubspot.
|
-- Additionally, the deal has not been offboarded in hubspot.
|
||||||
when
|
when deal_was_created_this_month and not deal_has_been_offboarded
|
||||||
deal_was_created_this_month
|
|
||||||
and not deal_has_been_offboarded
|
|
||||||
then '01-New'
|
then '01-New'
|
||||||
-- 02-Never Booked: The deal has been created before this month and has not
|
-- 02-Never Booked: The deal has been created before this month and has not
|
||||||
-- had any booking. Additionally, the deal has not been offboarded in hubspot.
|
-- had any booking. Additionally, the deal has not been offboarded in hubspot.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue