summaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/window/win_partition_functions.yql
blob: 4355228ad7a1af58fef250c3bb063ab3e2e0af3a (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
38
$data = [
    <|a: 1, b: 1, count: 1|>,
    <|a: 2, b: 1, count: 2|>,
    <|a: 2, b: 1, count: 2|>,
    <|a: NULL, b: 1, count: 2|>,
    <|a: NULL, b: 1, count: 2|>,
];

SELECT
    COUNT(*) OVER w1,
    RANK() OVER w1,
    DENSE_RANK() OVER w1,
    ROW_NUMBER() OVER w1,
    NTILE(3) OVER w1,
    PERCENT_RANK() OVER w1,
FROM
    AS_TABLE($data)
WINDOW
    w1 AS (
        PARTITION COMPACT BY
            b
        ORDER BY
            a ASC
    )
;

SELECT
    CUME_DIST() OVER w1,
FROM
    AS_TABLE($data)
WINDOW
    w1 AS (
        PARTITION COMPACT BY
            b
        ORDER BY
            a ASC
    )
;