2021-05-27 19:50:35 +00:00
|
|
|
DROP TABLE IF EXISTS grouping_sets;
|
|
|
|
|
2021-08-23 06:28:49 +00:00
|
|
|
CREATE TABLE grouping_sets(fact_1_id Int32, fact_2_id Int32, fact_3_id Int32, fact_4_id Int32, sales_value Int32) ENGINE = Memory;
|
2021-05-27 19:50:35 +00:00
|
|
|
|
2021-09-11 03:08:22 +00:00
|
|
|
SELECT fact_1_id, fact_3_id, sum(sales_value), count() from grouping_sets GROUP BY GROUPING SETS(fact_1_id, fact_3_id) ORDER BY fact_1_id, fact_3_id;
|
|
|
|
|
2021-08-23 06:28:49 +00:00
|
|
|
INSERT INTO grouping_sets
|
|
|
|
SELECT
|
2021-08-29 07:13:53 +00:00
|
|
|
number % 2 + 1 AS fact_1_id,
|
2021-08-23 06:28:49 +00:00
|
|
|
number % 5 + 1 AS fact_2_id,
|
|
|
|
number % 10 + 1 AS fact_3_id,
|
|
|
|
number % 10 + 1 AS fact_4_id,
|
|
|
|
number % 100 AS sales_value
|
|
|
|
FROM system.numbers limit 1000;
|
2021-05-27 19:50:35 +00:00
|
|
|
|
2022-04-21 14:11:58 +00:00
|
|
|
EXPLAIN PIPELINE
|
|
|
|
SELECT fact_1_id, fact_2_id, fact_3_id, SUM(sales_value) AS sales_value from grouping_sets
|
|
|
|
GROUP BY GROUPING SETS ((fact_1_id, fact_2_id), (fact_1_id, fact_3_id))
|
|
|
|
ORDER BY fact_1_id, fact_2_id, fact_3_id;
|
|
|
|
|
2021-08-23 06:28:49 +00:00
|
|
|
SELECT fact_1_id, fact_2_id, fact_3_id, SUM(sales_value) AS sales_value from grouping_sets
|
2021-09-11 03:08:22 +00:00
|
|
|
GROUP BY GROUPING SETS ((fact_1_id, fact_2_id), (fact_1_id, fact_3_id))
|
2021-08-23 06:28:49 +00:00
|
|
|
ORDER BY fact_1_id, fact_2_id, fact_3_id;
|
2021-05-27 19:50:35 +00:00
|
|
|
|
2021-08-23 06:28:49 +00:00
|
|
|
SELECT fact_1_id, fact_2_id, fact_3_id, fact_4_id, SUM(sales_value) AS sales_value from grouping_sets
|
2021-09-11 03:08:22 +00:00
|
|
|
GROUP BY GROUPING SETS ((fact_1_id, fact_2_id), (fact_3_id, fact_4_id))
|
2021-08-23 06:28:49 +00:00
|
|
|
ORDER BY fact_1_id, fact_2_id, fact_3_id, fact_4_id;
|
2021-05-27 19:50:35 +00:00
|
|
|
|
2021-09-11 03:08:22 +00:00
|
|
|
SELECT fact_1_id, fact_2_id, fact_3_id, SUM(sales_value) AS sales_value from grouping_sets
|
|
|
|
GROUP BY GROUPING SETS ((fact_1_id, fact_2_id), (fact_3_id), ())
|
|
|
|
ORDER BY fact_1_id, fact_2_id, fact_3_id;
|
|
|
|
|
2021-08-23 06:28:49 +00:00
|
|
|
SELECT
|
|
|
|
fact_1_id,
|
|
|
|
fact_3_id,
|
|
|
|
SUM(sales_value) AS sales_value
|
|
|
|
FROM grouping_sets
|
2021-09-11 03:08:22 +00:00
|
|
|
GROUP BY grouping sets ((fact_1_id), (fact_1_id, fact_3_id)) WITH TOTALS
|
2022-04-21 13:41:59 +00:00
|
|
|
ORDER BY fact_1_id, fact_3_id; -- { serverError NOT_IMPLEMENTED }
|
2021-05-27 19:50:35 +00:00
|
|
|
|
2021-08-23 06:28:49 +00:00
|
|
|
SELECT
|
|
|
|
fact_1_id,
|
|
|
|
fact_3_id,
|
|
|
|
SUM(sales_value) AS sales_value
|
|
|
|
FROM grouping_sets
|
2021-09-11 03:08:22 +00:00
|
|
|
GROUP BY grouping sets (fact_1_id, (fact_1_id, fact_3_id)) WITH TOTALS
|
2022-04-21 13:41:59 +00:00
|
|
|
ORDER BY fact_1_id, fact_3_id; -- { serverError NOT_IMPLEMENTED }
|
2021-05-27 19:50:35 +00:00
|
|
|
|
|
|
|
DROP TABLE grouping_sets;
|