From 95ea88c1e632a0d75d9953cf1c98e847ca04fe4e Mon Sep 17 00:00:00 2001 From: popcorny Date: Tue, 4 Feb 2025 14:36:14 +0800 Subject: [PATCH 1/2] Add promotion information Signed-off-by: popcorny --- models/customers.sql | 8 +++++--- models/staging/stg_payments.sql | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/models/customers.sql b/models/customers.sql index 9aedd70a2..1d4cb29aa 100644 --- a/models/customers.sql +++ b/models/customers.sql @@ -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 @@ -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 @@ -63,7 +65,7 @@ final as ( left join customer_payments on customers.customer_id = customer_payments.customer_id - + where has_promoted_orders = true ) select * from final diff --git a/models/staging/stg_payments.sql b/models/staging/stg_payments.sql index 331ed4871..0c296b4d8 100644 --- a/models/staging/stg_payments.sql +++ b/models/staging/stg_payments.sql @@ -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 From 879b4760041a4eda19b275eb9980e7ecf19f0f56 Mon Sep 17 00:00:00 2001 From: Karen Hsieh Date: Tue, 25 Mar 2025 16:27:38 +0800 Subject: [PATCH 2/2] remove where condition --- models/customers.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/models/customers.sql b/models/customers.sql index 1d4cb29aa..5ae92696d 100644 --- a/models/customers.sql +++ b/models/customers.sql @@ -65,7 +65,6 @@ final as ( left join customer_payments on customers.customer_id = customer_payments.customer_id - where has_promoted_orders = true ) select * from final