forked from dbt-labs/jaffle-shop-classic
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74d472b
commit 3511e9c
Showing
4 changed files
with
21 additions
and
9 deletions.
There are no files selected for viewing
12 changes: 4 additions & 8 deletions
12
jaffle_shop/models/final/finance/fnl_finance_customerreturnstotal.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
GROUP BY orders.customer_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters