Skip to content

Instantly share code, notes, and snippets.

@kzzzr
Created January 27, 2022 20:28
Show Gist options
  • Save kzzzr/5cccc74f6d9eeb189ae6fdba1b2ec14a to your computer and use it in GitHub Desktop.
Save kzzzr/5cccc74f6d9eeb189ae6fdba1b2ec14a to your computer and use it in GitHub Desktop.
CTE usage showcase
{{
config(
materialized='ephemeral'
)
}}
WITH accepted AS (
SELECT DISTINCT
request_id
, LAST_VALUE(car_id IGNORE NULLS) OVER
(PARTITION BY request_id ORDER BY event_ts_utc ASC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) as car_id
FROM {{ ref('flt_orders_logs') }}
WHERE event_status in ('accepted')
GROUP BY
request_id
, car_id
, event_ts_utc
)
SELECT
reserved.request_id
, DECODE(reserved.car_id, accepted.car_id, false, true) as is_prebook_to_asap
FROM {{ ref('int_requests_first_reservations') }} as reserved
LEFT JOIN accepted USING(request_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment