2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS Test;
|
2018-03-01 06:21:15 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
CREATE TABLE Test (
|
2018-03-01 06:21:15 +00:00
|
|
|
createdDate Date,
|
|
|
|
str String,
|
|
|
|
key Enum8('A' = 0, 'B' = 1, 'ALL' = 2),
|
|
|
|
a Int64
|
|
|
|
)
|
|
|
|
ENGINE = MergeTree(createdDate, str, 8192);
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
INSERT INTO Test VALUES ('2000-01-01', 'hello', 'A', 123);
|
2018-03-01 06:21:15 +00:00
|
|
|
|
|
|
|
SET max_threads = 1;
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
CREATE VIEW TestView AS
|
2018-03-01 06:21:15 +00:00
|
|
|
SELECT str, key, sumIf(a, 0) AS sum
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM Test
|
2018-03-01 06:21:15 +00:00
|
|
|
GROUP BY str, key
|
|
|
|
|
|
|
|
UNION ALL
|
|
|
|
|
|
|
|
SELECT str AS str, CAST('ALL' AS Enum8('A' = 0, 'B' = 1, 'ALL' = 2)) AS key, sumIf(a, 0) AS sum
|
2019-04-16 14:13:13 +00:00
|
|
|
FROM Test
|
2018-03-01 06:21:15 +00:00
|
|
|
GROUP BY str;
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT * FROM TestView;
|
2018-03-01 06:21:15 +00:00
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE TestView;
|
|
|
|
DROP TABLE Test;
|