From 8da0377cd98b4a832a248f821fcbaec821743a3b Mon Sep 17 00:00:00 2001 From: "structured-bot-beta[bot]" <183862570+structured-bot-beta[bot]@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:37:27 +0000 Subject: [PATCH 1/2] Update jaffle_shop/models/customer_total_amount_spent.sql [1728502639062] --- .../models/customer_total_amount_spent.sql | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 jaffle_shop/models/customer_total_amount_spent.sql diff --git a/jaffle_shop/models/customer_total_amount_spent.sql b/jaffle_shop/models/customer_total_amount_spent.sql new file mode 100644 index 0000000..92fcf5e --- /dev/null +++ b/jaffle_shop/models/customer_total_amount_spent.sql @@ -0,0 +1,37 @@ +{{ + config( + materialized='table' + ) +}} + +with orders as ( + select * from {{ ref('stg_orders') }} +), + +order_amounts as ( + select + customer_id, + order_id, + amount + from orders +), + +customer_total_amount as ( + select + customer_id, + sum(amount) as total_amount_spent + from order_amounts + group by customer_id +), + +final as ( + select + c.customer_id, + c.first_name, + c.last_name, + coalesce(cta.total_amount_spent, 0) as total_amount_spent + from {{ ref('stg_customers') }} c + left join customer_total_amount cta using (customer_id) +) + +select * from final \ No newline at end of file From f48f9ab9b41f41b2875d82f1ef232ac34f197622 Mon Sep 17 00:00:00 2001 From: DBT AI Assistant Date: Wed, 9 Oct 2024 19:37:29 +0000 Subject: [PATCH 2/2] Add model to calculate total amount spent per customer [1728502639062]