Skip to content

Commit 1967696

Browse files
committed
Add promotion information
Signed-off-by: popcorny <[email protected]>
1 parent 8d75fcf commit 1967696

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

models/customers.sql

+5-3
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ customer_payments as (
3434

3535
select
3636
orders.customer_id,
37-
sum(amount)::bigint as total_amount
37+
sum(amount)::bigint as total_amount,
38+
bool_or(is_promotion) as has_promoted_orders
3839

3940
from payments
4041

@@ -54,7 +55,8 @@ final as (
5455
customer_orders.first_order,
5556
customer_orders.most_recent_order,
5657
customer_orders.number_of_orders,
57-
customer_payments.total_amount as customer_lifetime_value
58+
customer_payments.total_amount as customer_lifetime_value,
59+
customer_payments.has_promoted_orders
5860

5961
from customers
6062

@@ -63,7 +65,7 @@ final as (
6365

6466
left join customer_payments
6567
on customers.customer_id = customer_payments.customer_id
66-
68+
where has_promoted_orders = true
6769
)
6870

6971
select * from final

models/staging/stg_payments.sql

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ renamed as (
1616
payment_method,
1717

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

2122
from source
2223

0 commit comments

Comments
 (0)