aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/tests/sql/suites/tpch/q13.sql
blob: e94f36a5450126e0343739bea0deefc8bef97ac4 (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
-- TPC-H/TPC-R Customer Distribution Query (Q13)
-- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
-- using 1680793381 as a seed to the RNG

$orders = (
    select
        o_orderkey,
        o_custkey
    from
        plato.orders
    where
        o_comment NOT LIKE "%unusual%requests%"
);
select
    c_count as c_count,
    count(*) as custdist
from
    (
        select
            c.c_custkey as c_custkey,
            count(o.o_orderkey) as c_count
        from
            plato.customer as c left outer join $orders as o on
                c.c_custkey = o.o_custkey
        group by
            c.c_custkey
    ) as c_orders
group by
    c_count
order by
    custdist desc,
    c_count desc;