Addressed comments
This commit is contained in:
parent
3f08229256
commit
c60bfc6ccb
1 changed files with 11 additions and 7 deletions
|
|
@ -11,15 +11,18 @@
|
|||
)
|
||||
}}
|
||||
with
|
||||
-- Selects the most recent product bundle per accommodation per day
|
||||
-- Order by the most recent product bundle per accommodation per day
|
||||
latest_daily_bundle as (
|
||||
select distinct on (id_accommodation, effective_start_date_utc) *
|
||||
select
|
||||
*,
|
||||
row_number() over (
|
||||
partition by id_accommodation, effective_start_date_utc
|
||||
order by
|
||||
effective_start_date_utc desc, -- Prefers the latest effective start date
|
||||
original_starts_at_utc desc, -- In case of ties, prefers the most recent original start
|
||||
coalesce(original_ends_at_utc, {{ var("end_of_time") }}) desc
|
||||
) as rn
|
||||
from {{ ref("int_core__accommodation_to_product_bundle") }}
|
||||
order by
|
||||
id_accommodation, -- Ensures we are filtering per accommodation
|
||||
effective_start_date_utc desc, -- Prefers the latest effective start date
|
||||
original_starts_at_utc desc, -- In case of ties, prefers the most recent original start
|
||||
coalesce(original_ends_at_utc, {{ var("end_of_time") }}) desc
|
||||
)
|
||||
select
|
||||
-- Unique Key --
|
||||
|
|
@ -50,6 +53,7 @@ inner join
|
|||
on bs.id_user_product_bundle = ldb.id_user_product_bundle
|
||||
and date >= ldb.effective_start_date_utc
|
||||
and date < coalesce(ldb.effective_end_date_utc, {{ var("end_of_time") }})
|
||||
and ldb.rn = 1
|
||||
left join
|
||||
{{ ref("int_kpis__dimension_daily_accommodation") }} as icmas
|
||||
on uh.id_deal = icmas.id_deal
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue