Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. with from_a as (
  2. select uuid, api_utc, version
  3. from A
  4. ), from_b as (
  5. select levuuid, event_utc
  6. from B
  7. ), build_c as (
  8. select
  9. uuid, levuuid,
  10. abs(api_utc - event_utc) as time_diff,
  11. version
  12. from
  13. from_a
  14. full outer join
  15. from_b
  16. on from_a.uuid = from_b.levuuid
  17. ), ordered_build_c as (
  18. select *, row_number over (partition by coalesce(uuid, levuuid)) order by time_diff as rank_number
  19. )
  20. select
  21. coalesce(uuid, levuuid),
  22. version
  23. from
  24. ordered_build_c
  25. where rank_number = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement