Please imagine following scenario:
customers
id | name | active
orders
id | value | status | customer_id | created_at
I am trying to avoid creating a new view or PDT, in order to get orders joined to the patients but only first row.
I added dimension called customer_order_no
with the following SQL:
ROW_NUMBER() OVER(PARTITION BY orders.customer_id ORDER BY orders.created_at ASC
Then in the model file I created a join:
join: orders {
fields: []
type: left_outer
sql_on: ${customer.customer_id} = ${orders.customer_id} AND ${orders.customer_order_no} = 1 ;;
relationship: one_to_one
}
Of course then I realised I can’t put window functions in JOINs or WHERE clauses. I would want to avoid another PDT, so I’m just throwing it out here…
Anybody has a nice way of achieving it?