Created
January 27, 2022 20:28
-
-
Save kzzzr/5cccc74f6d9eeb189ae6fdba1b2ec14a to your computer and use it in GitHub Desktop.
CTE usage showcase
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ | |
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