yql-15636.sql 676 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* syntax version 1 */
  2. /* postgres can not */
  3. use plato;
  4. insert into @tmp
  5. select
  6. Just('foo') as driver_license_pd_id,
  7. 'bar' as order_id,
  8. '1' as user_phone_pd_id,
  9. '2' as utc_order_dttm;
  10. commit;
  11. SELECT
  12. driver_license_pd_id,
  13. user_phone_pd_id,
  14. utc_order_dttm,
  15. order_id,
  16. LEAD(
  17. <|"order_id": order_id, "order_dttm": utc_order_dttm|>,
  18. 1
  19. ) OVER (
  20. PARTITION BY user_phone_pd_id
  21. ORDER BY utc_order_dttm
  22. ) AS next_user_order,
  23. LEAD(
  24. <|"order_id": order_id|>,
  25. 1
  26. ) OVER (
  27. PARTITION BY driver_license_pd_id
  28. ORDER BY utc_order_dttm
  29. ) AS next_driver_order,
  30. FROM @tmp;