54 lines
2 KiB
MySQL
54 lines
2 KiB
MySQL
|
|
{% set min_date = "2022-01-01" %}
|
||
|
|
{% set dimensions = ("global", "by_billing_country") %}
|
||
|
|
-- "by_number_of_listings" excluded on purpose - there's differences because of daily
|
||
|
|
-- segmentation
|
||
|
|
with
|
||
|
|
new_mtd_check_out_bookings as (
|
||
|
|
select end_date as date, dimension, dimension_value, check_out_bookings
|
||
|
|
from {{ ref("int_kpis__aggregated_mtd_check_out_bookings") }}
|
||
|
|
where
|
||
|
|
end_date >= '{{ min_date }}'
|
||
|
|
and dimension in {{ dimensions }}
|
||
|
|
and dimension_value <> 'UNSET'
|
||
|
|
),
|
||
|
|
new_monthly_check_out_bookings as (
|
||
|
|
select end_date as date, dimension, dimension_value, check_out_bookings
|
||
|
|
from {{ ref("int_kpis__aggregated_monthly_check_out_bookings") }}
|
||
|
|
where
|
||
|
|
end_date >= '{{ min_date }}'
|
||
|
|
and dimension in {{ dimensions }}
|
||
|
|
and dimension_value <> 'UNSET'
|
||
|
|
),
|
||
|
|
new_check_out_bookings as (
|
||
|
|
select *
|
||
|
|
from new_mtd_check_out_bookings
|
||
|
|
union all
|
||
|
|
select *
|
||
|
|
from new_monthly_check_out_bookings
|
||
|
|
),
|
||
|
|
old_check_out_bookings as (
|
||
|
|
select date, dimension, dimension_value, check_out_bookings
|
||
|
|
from {{ ref("int_core__mtd_check_out_bookings_metric") }}
|
||
|
|
where date >= '{{ min_date }}' and dimension in {{ dimensions }}
|
||
|
|
),
|
||
|
|
comparison as (
|
||
|
|
select
|
||
|
|
coalesce(o.date, n.date) as date,
|
||
|
|
coalesce(o.dimension, n.dimension) as dimension,
|
||
|
|
coalesce(o.dimension_value, n.dimension_value) as dimension_value,
|
||
|
|
o.check_out_bookings as old_check_out_bookings,
|
||
|
|
n.check_out_bookings as new_check_out_bookings,
|
||
|
|
coalesce(o.check_out_bookings, 0)
|
||
|
|
- coalesce(n.check_out_bookings, 0) as diff
|
||
|
|
from old_check_out_bookings o
|
||
|
|
full outer join
|
||
|
|
new_check_out_bookings n
|
||
|
|
on o.date = n.date
|
||
|
|
and o.dimension = n.dimension
|
||
|
|
and o.dimension_value = n.dimension_value
|
||
|
|
)
|
||
|
|
select *
|
||
|
|
from comparison
|
||
|
|
where diff <> 0
|
||
|
|
order by date desc, abs(diff) desc
|