-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add fct_order_items model #3
base: master
Are you sure you want to change the base?
Changes from all commits
0b8e1b6
fa1de7a
3a3d419
d959ef8
6bc99fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{# | ||
create a fct_order_items table joining orders to order items. | ||
select all fields from order items and join in the order_date, | ||
email and customer_id from the orders table | ||
#} | ||
with orderitems as ( | ||
|
||
select * from {{ ref('order_items_upload') }} | ||
|
||
), | ||
|
||
orders as ( | ||
|
||
eogilvy12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
select * from {{ ref('orders_upload') }} | ||
|
||
), | ||
|
||
final as ( | ||
|
||
select | ||
orderitems.id as order_item_id, | ||
orderitems.order_id, | ||
orderitems.price, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is not typical to list out explicit order_item fields since you have already done that in the stg model. typically, it will be |
||
orderitems.quantity, | ||
orderitems.size, | ||
orderitems.color, | ||
orderitems.product_id, | ||
orders.created_at, | ||
orders.email, | ||
orders.customer_id | ||
|
||
from orderitems | ||
|
||
inner join orders on orderitems.order_id = orders.id | ||
|
||
) | ||
|
||
select * from final |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
with orders as ( | ||
|
||
select * from {{ ref('stg_orders') }} | ||
|
||
), | ||
|
||
orderitems as ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you use the order_items CTE anywhere in this model so you can remove |
||
|
||
select * from {{ ref('stg_order_items') }} | ||
), | ||
|
||
calc as ( | ||
|
||
select | ||
orders.customer_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is another situation where you want to we can talk about this in more detail during our check in tomorrow! |
||
lag(orders.created_at, 1) [ignore nulls] | ||
over (partition by orders.customer_id | ||
order by orders.created_at desc) as created_at_prev, | ||
created_at | ||
from orders | ||
), | ||
|
||
final as ( | ||
select | ||
JDW818 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
datediff(month, created_at, created_at_prev) as months_since_prior_order | ||
from calc | ||
) | ||
|
||
select * from final |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be ref the staging models that you built!
stg_orders
andstg_order_items