Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save portovep/0adf42124568567bb98e0c7145098f39 to your computer and use it in GitHub Desktop.
Save portovep/0adf42124568567bb98e0c7145098f39 to your computer and use it in GitHub Desktop.
Example of a dbt intermediate model
with
height as (
select * from {{ dbt_unit_testing.ref('stg_gym_app__height') }}
),
weight as (
select * from {{ dbt_unit_testing.ref('stg_gym_app__weight') }}
),
enrich_with_lasted_height_recorded_before_the_weight_measurement as (
select
weight.created_date,
user_id,
weight,
(select height
from height
where height.created_date < weight.created_date and
height.user_id = weight.user_id
order by height.created_date DESC
limit 1) as height
from weight
)
select * from enrich_with_lasted_height_recorded_before_the_weight_measurement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment