diff --git a/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql b/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql index a3d2c59dc..a832f0dae 100644 --- a/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql +++ b/jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql @@ -1,18 +1,14 @@ {% set return_states = ['returned', 'return_pending'] %} select - custs.customer_id + orders.customer_id {% for return_state in return_states -%} - , SUM(payments.amount_dollars) FILTER (WHERE orders.status =' {{ return_state }}') AS {{ return_state }}_amount_dollars + , SUM(orders.amount_dollars) FILTER (WHERE orders.status =' {{ return_state }}') AS {{ return_state }}_amount_dollars {% endfor -%} - , SUM(payments.amount_dollars) AS sum_return_amount_dollars + , SUM(orders.amount_dollars) AS sum_return_amount_dollars from {{ ref('wh_orders') }} AS orders - left join {{ ref('wh_customers') }} AS custs - on custs.customer_id = orders.customer_id - left join {{ ref('stg_payments') }} AS payments - on payments.order_id = orders.order_id where orders.status IN ('returned', 'return_pending') -GROUP BY customer_id \ No newline at end of file +GROUP BY orders.customer_id \ No newline at end of file diff --git a/jaffle_shop/models/staging/src_seed/_models.yml b/jaffle_shop/models/staging/src_seed/_models.yml index 46abf1529..981a7e3b9 100644 --- a/jaffle_shop/models/staging/src_seed/_models.yml +++ b/jaffle_shop/models/staging/src_seed/_models.yml @@ -2,8 +2,10 @@ version: 2 models: - name: stg_orders + description: staging layer for all orders columns: - name: order_id + description: Primary Key tests: - unique - not_null @@ -13,8 +15,10 @@ models: values: ['placed', 'shipped', 'completed', 'return_pending', 'returned'] - name: stg_payments + description: staging layer for all payments with a FK to order columns: - name: payment_id + description: Primary Key tests: - unique - not_null @@ -22,3 +26,12 @@ models: tests: - accepted_values: values: ['credit_card', 'coupon', 'bank_transfer', 'gift_card'] + + - name: stg_customers + description: staging layer for all customers, PII hashed + columns: + - name: customer_id + description: Primary Key + tests: + - unique + - not_null \ No newline at end of file diff --git a/jaffle_shop/models/staging/src_seed/sensitive/_models.yml b/jaffle_shop/models/staging/src_seed/sensitive/_models.yml index 6649bf8af..e75f52c6c 100644 --- a/jaffle_shop/models/staging/src_seed/sensitive/_models.yml +++ b/jaffle_shop/models/staging/src_seed/sensitive/_models.yml @@ -2,8 +2,11 @@ version: 2 models: - name: stg_customers_pii + description: > + Table that includes all info about all customers, with PII hashed columns: - name: customer_id + description: Primary Key tests: - unique - not_null diff --git a/jaffle_shop/models/warehouse/wh_orders.sql b/jaffle_shop/models/warehouse/wh_orders.sql index cbb293491..b693d3775 100644 --- a/jaffle_shop/models/warehouse/wh_orders.sql +++ b/jaffle_shop/models/warehouse/wh_orders.sql @@ -43,7 +43,7 @@ final as ( {% endfor -%} - order_payments.total_amount as amount + order_payments.total_amount as amount_dollars from orders