Skip to content

[Demo] Understand if a customer has promoted orders #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions models/customers.sql
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ customer_payments as (

select
orders.customer_id,
sum(amount)::bigint as total_amount
sum(amount)::bigint as total_amount,
bool_or(is_promotion) as has_promoted_orders

from payments

Expand All @@ -54,7 +55,8 @@ final as (
customer_orders.first_order,
customer_orders.most_recent_order,
customer_orders.number_of_orders,
customer_payments.total_amount as customer_lifetime_value
customer_payments.total_amount as customer_lifetime_value,
customer_payments.has_promoted_orders

from customers

Expand All @@ -63,7 +65,6 @@ final as (

left join customer_payments
on customers.customer_id = customer_payments.customer_id

)

select * from final
3 changes: 2 additions & 1 deletion models/staging/stg_payments.sql
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ renamed as (
payment_method,

-- `amount` is currently stored in cents, so we convert it to dollars
amount / 100 as amount
amount / 100 as amount,
payment_method == 'coupon' as is_promotion

from source

Expand Down
Loading