Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- with from_a as (
- select uuid, api_utc, version
- from A
- ), from_b as (
- select levuuid, event_utc
- from B
- ), build_c as (
- select
- uuid, levuuid,
- abs(api_utc - event_utc) as time_diff,
- version
- from
- from_a
- full outer join
- from_b
- on from_a.uuid = from_b.levuuid
- ), ordered_build_c as (
- select *, row_number over (partition by coalesce(uuid, levuuid)) order by time_diff as rank_number
- )
- select
- coalesce(uuid, levuuid),
- version
- from
- ordered_build_c
- where rank_number = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement