Skip to content
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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions models/example/fct_order_items.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{#
create a `fct_order_items` table joining orders to customers to get the
`order_date` and `email` and `customer_id` on the order table
#}
with source_1 as (

select * from {{ ref('orders_upload') }}

),

source_2 as (

eogilvy12 marked this conversation as resolved.
Show resolved Hide resolved
select * from {{ ref('customers_upload') }}

)

final as (

select
source_1.created_at,
source_2.email,
source_2.customer_id,

from source_1

left join source_2 on source_1.customer_id = source_2.id

)

select * from renamed
30 changes: 30 additions & 0 deletions models/example/order_calculations.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
with source1 as (
JDW818 marked this conversation as resolved.
Show resolved Hide resolved

select * from {{ ref('customers_upload') }}
JDW818 marked this conversation as resolved.
Show resolved Hide resolved

),

source2 as (

select * from {{ ref('orders_upload') }}
),

calc as (

select
source1.id as customer_id,
lag(source2.created_at, 1) [ignore nulls]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to pull from stg_orders and stg_order_items

your query can look like:

select
    items.*,
    orders.email,
    orders.customer_id,
    orders.order_date
from items
inner join order using (order_id)

and then do any of the additional modeling that you want for the window functions

over (partition by source1.id
order by source2.created_at desc) as created_at_prev,
created_at
from source1

inner join source2

on source1.id = source2.customer_id

)

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