51 lines
1.5 KiB
MySQL
51 lines
1.5 KiB
MySQL
|
|
/*
|
||
|
|
This model pivots the data of the different mtd metrics models to get
|
||
|
|
previous year for each line & computing relative increment. --
|
||
|
|
*/
|
||
|
|
|
||
|
|
{{ config(materialized="table", unique_key="date") }}
|
||
|
|
with
|
||
|
|
int_core__mtd_booking_metrics as (
|
||
|
|
select * from {{ ref("int_core__mtd_booking_metrics") }}
|
||
|
|
),
|
||
|
|
int_dates_mtd as (select * from {{ ref("int_dates_mtd") }}),
|
||
|
|
|
||
|
|
plain_kpi_combination as (
|
||
|
|
select
|
||
|
|
d.year,
|
||
|
|
d.month,
|
||
|
|
d.day,
|
||
|
|
d.is_end_of_month,
|
||
|
|
d.is_current_month,
|
||
|
|
d.date,
|
||
|
|
bookings.created_bookings,
|
||
|
|
bookings.check_out_bookings,
|
||
|
|
bookings.cancelled_bookings
|
||
|
|
from int_dates_mtd d
|
||
|
|
left join int_core__mtd_booking_metrics bookings
|
||
|
|
on d.date = bookings.date
|
||
|
|
)
|
||
|
|
select
|
||
|
|
current.year,
|
||
|
|
current.month,
|
||
|
|
current.day,
|
||
|
|
current.is_end_of_month,
|
||
|
|
current.is_current_month,
|
||
|
|
current.date,
|
||
|
|
previous_year.date as previous_year_date,
|
||
|
|
|
||
|
|
-- BOOKINGS --
|
||
|
|
{{ calculate_safe_relative_increment('created_bookings') }},
|
||
|
|
{{ calculate_safe_relative_increment('check_out_bookings') }},
|
||
|
|
{{ calculate_safe_relative_increment('cancelled_bookings') }}
|
||
|
|
|
||
|
|
from plain_kpi_combination current
|
||
|
|
left join plain_kpi_combination previous_year
|
||
|
|
on current.month = previous_year.month
|
||
|
|
and current.year = previous_year.year + 1
|
||
|
|
where
|
||
|
|
(
|
||
|
|
current.is_end_of_month = 1
|
||
|
|
or (current.is_current_month = 1 and current.day = previous_year.day)
|
||
|
|
)
|