0% found this document useful (0 votes)
25 views1 page

2.3.10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views1 page

2.3.10

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

stg_payments

select
id as payment_id,
orderid as order_id,
paymentmethod as payment_method,
status,

-- amount is stored in cents, convert it to dollars


{{ cents_to_dollars('amount') }} as amount,
created as created_at

from {{ source('stripe','payment')}}

-------------------------------------------------------------------------

fact_orders

with orders as (
select * from {{ ref('stg_orders' )}}
),

payments as (
select * from {{ ref('stg_payments') }}
),

order_payments as (
select
order_id,
sum(case when status = 'success' then amount end) as amount

from payments
group by 1
),

final as (

select
orders.order_id,
orders.customer_id,
orders.order_date,
coalesce(order_payments.amount, 0) as amount

from orders
left join order_payments using (order_id)
)

select * from final

You might also like