ClickHouse/tests/queries/0_stateless/03146_tpc_ds_grouping.sql
2024-05-06 14:36:04 +02:00

72 lines
1.4 KiB
SQL

-- https://github.com/ClickHouse/ClickHouse/issues/46335
SET allow_experimental_analyzer = 1;
SELECT
key_a + key_b AS d,
rank() OVER () AS f
FROM
(
SELECT
rand() % 10 AS key_a,
rand(1) % 5 AS key_b,
number
FROM numbers(100)
)
GROUP BY
key_a,
key_b
WITH ROLLUP
ORDER BY multiIf(d = 0, key_a, NULL) ASC
FORMAT Null;
SELECT
key_a + key_b AS d,
rank() OVER (PARTITION BY key_a + key_b) AS f
FROM
(
SELECT
rand() % 10 AS key_a,
rand(1) % 5 AS key_b,
number
FROM numbers(100)
)
GROUP BY
key_a,
key_b
WITH ROLLUP
ORDER BY multiIf(d = 0, key_a, NULL) ASC
FORMAT Null;
SELECT
grouping(key_a) + grouping(key_b) AS d,
rank() OVER (PARTITION BY grouping(key_a) + grouping(key_b), multiIf(grouping(key_b) = 0, key_a, NULL)) AS f
FROM
(
SELECT
rand() % 10 AS key_a,
rand(1) % 5 AS key_b,
number
FROM numbers(100)
)
GROUP BY
key_a,
key_b
WITH ROLLUP
ORDER BY multiIf(d = 0, key_a, NULL) ASC
FORMAT Null;
SELECT grouping(key_a) + grouping(key_b) AS d
FROM
(
SELECT
rand() % 10 AS key_a,
rand(toLowCardinality(1)) % 5 AS key_b,
number
FROM numbers(100)
)
GROUP BY
key_a,
key_b
WITH ROLLUP
FORMAT Null;