Skip to content

Commit

Permalink
Remove unnecessary join and Select only necessary columns in place of…
Browse files Browse the repository at this point in the history
… Select *
  • Loading branch information
joshuadias2212 committed Apr 11, 2024
1 parent 8b84d4b commit 598933f
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions jaffle_shop/models/final/finance/fnl_returned_order_value.sql
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
WITH returned_orders AS (
SELECT *
SELECT
orders.customer_id AS customer_id
orders.amount as total_amount
FROM {{ ref('wh_orders') }}
WHERE status = 'returned'
)

customers AS (
SELECT *
FROM {{ref('stg_customers') }}
WHERE orders.status = 'returned'
)

SELECT
customer_id
, SUM(COALESCE(total_amount, 0) AS total_value
FROM returned_orders
LEFT JOIN customers
ON returned_orders.customer_id = customers.customer_id
GROUP BY customer_id

0 comments on commit 598933f

Please sign in to comment.