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.
Add new models and add _models.yml files
- Loading branch information
1 parent
b6772e5
commit 46cada8
Showing
8 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: fnl_finance_customerreturnstotal | ||
description: > | ||
This table gives one row per customer, with the total of their completed returns, | ||
pending_returns and the sum of the 2 | ||
columns: | ||
- name: customer_id | ||
description: primary key | ||
tests: | ||
- unique | ||
- not_null |
18 changes: 18 additions & 0 deletions
18
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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{% set return_states = ['returned', 'return_pending'] %} | ||
|
||
select | ||
custs.customer_id | ||
|
||
{% for return_state in return_states -%} | ||
, SUM(payments.amount_dollars) FILTER (WHERE orders.status =' {{ return_state }}') AS {{ return_state }}_amount_dollars | ||
{% endfor -%} | ||
|
||
, SUM(payments.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 |
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
version: 2 | ||
|
||
models: | ||
- name: fnl_sales_newcustomerhistory | ||
description: > | ||
This table gives one row per truncated month with the count | ||
of customers that have created their first order within this month | ||
columns: | ||
- name: first_order_month | ||
description: primary key | ||
tests: | ||
- unique | ||
- not_null |
4 changes: 4 additions & 0 deletions
4
jaffle_shop/models/final/sales/fnl_sales_newcustomerhistory.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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
select | ||
date_trunc('month', first_order) AS first_order_month | ||
, count(*) AS number_customers | ||
from {{ ref('wh_customers') }} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
version: 2 |
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
File renamed without changes.