aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/yql-15636.sql
blob: b9efdb2c56c3568c2f0fd9edb826f715b1f6f9a0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/* syntax version 1 */
/* postgres can not */
use plato;

insert into @tmp
select
  Just('foo') as driver_license_pd_id,
  'bar' as order_id,
  '1' as user_phone_pd_id,
  '2' as utc_order_dttm;
commit;  



SELECT
    driver_license_pd_id,
    user_phone_pd_id,
    utc_order_dttm,
    order_id,

    LEAD(
        <|"order_id": order_id, "order_dttm": utc_order_dttm|>,
        1
    ) OVER (
        PARTITION BY user_phone_pd_id
        ORDER BY utc_order_dttm
    ) AS next_user_order,

    LEAD(
        <|"order_id": order_id|>,
        1
    ) OVER (
        PARTITION BY driver_license_pd_id
        ORDER BY utc_order_dttm
    ) AS next_driver_order,
    
FROM @tmp;