data-dwh-dbt-project/models/reporting/revenue/guest_fees.sql
2024-03-12 11:37:48 +01:00

18 lines
731 B
SQL

with
date_master as (select * from {{ ref("int_dates") }}),
fee_txns as (
select vtp.*, vpt.*, p.*, ps."Name"
from sync_core."VerificationToPayment" vtp
left join
sync_core."VerificationPaymentType" vpt
on vtp."VerificationPaymentTypeId" = vpt."Id"
left join sync_core."Payment" p on vtp."PaymentId" = p."PaymentId"
left join sync_core."PaymentStatus" ps on p."PaymentStatusId" = ps."Id"
where vpt."Name" = 'Fee'
)
select date_day, sum("Amount")
from date_master
left join fee_txns on date_master.date_day = cast(fee_txns."PaymentDueDate" as date)
where date_day between '2022-01-01' and '2024-12-31'
group by date_master.date_day
order by 2 desc