ClickHouse/tests/queries/0_stateless/00047_stored_aggregates_complex.sql

65 lines
1.7 KiB
MySQL
Raw Normal View History

DROP TABLE IF EXISTS stored_aggregates;
2014-06-06 18:00:52 +00:00
CREATE TABLE stored_aggregates
2014-06-06 18:00:52 +00:00
(
d Date,
k1 UInt64,
k2 String,
Sum AggregateFunction(sum, UInt64),
Avg AggregateFunction(avg, UInt64),
Uniq AggregateFunction(uniq, UInt64),
Any AggregateFunction(any, String),
AnyIf AggregateFunction(anyIf, String, UInt8),
Quantiles AggregateFunction(quantiles(0.5, 0.9), UInt64),
GroupArray AggregateFunction(groupArray, String)
)
ENGINE = AggregatingMergeTree(d, (d, k1, k2), 8192);
INSERT INTO stored_aggregates
2014-06-06 18:00:52 +00:00
SELECT
toDate('2014-06-01') AS d,
intDiv(number, 100) AS k1,
toString(intDiv(number, 10)) AS k2,
sumState(number) AS Sum,
avgState(number) AS Avg,
uniqState(toUInt64(number % 7)) AS Uniq,
anyState(toString(number)) AS Any,
anyIfState(toString(number), number % 7 = 0) AS AnyIf,
quantilesState(0.5, 0.9)(number) AS Quantiles,
groupArrayState(toString(number)) AS GroupArray
FROM
(
SELECT * FROM system.numbers LIMIT 1000
)
GROUP BY d, k1, k2
ORDER BY d, k1, k2;
SELECT d, k1, k2,
sumMerge(Sum), avgMerge(Avg), uniqMerge(Uniq),
anyMerge(Any), anyIfMerge(AnyIf),
2022-05-26 23:59:45 +00:00
arrayMap(x -> round(x, 6), quantilesMerge(0.5, 0.9)(Quantiles)),
2014-06-06 18:00:52 +00:00
groupArrayMerge(GroupArray)
FROM stored_aggregates
2014-06-06 18:00:52 +00:00
GROUP BY d, k1, k2
ORDER BY d, k1, k2;
SELECT d, k1,
sumMerge(Sum), avgMerge(Avg), uniqMerge(Uniq),
anyMerge(Any), anyIfMerge(AnyIf),
2022-05-26 23:59:45 +00:00
arrayMap(x -> round(x, 6), quantilesMerge(0.5, 0.9)(Quantiles)),
2014-06-06 18:00:52 +00:00
groupArrayMerge(GroupArray)
FROM stored_aggregates
2014-06-06 18:00:52 +00:00
GROUP BY d, k1
ORDER BY d, k1;
SELECT d,
sumMerge(Sum), avgMerge(Avg), uniqMerge(Uniq),
anyMerge(Any), anyIfMerge(AnyIf),
2022-05-26 23:59:45 +00:00
arrayMap(x -> round(x, 6), quantilesMerge(0.5, 0.9)(Quantiles)),
2014-06-06 18:00:52 +00:00
groupArrayMerge(GroupArray)
FROM stored_aggregates
2014-06-06 18:00:52 +00:00
GROUP BY d
ORDER BY d;
2014-11-22 20:56:14 +00:00
DROP TABLE stored_aggregates;