Skip to Content
Developer GuideFunctionsAggregate function

Aggregate Functions

Function Name Description Syntax
count Counts the number of rows or non-NULL values count(expr), COUNT(DISTINCT expr), count(), count(*)
any(x) Returns the first encountered value, result is non-deterministic any(column)
anyHeavy(x) Returns frequently occurring values based on the heavy hitters algorithm. Usually non-deterministic results anyHeavy(column)
anyLast(x) Returns the last encountered value, result is non-deterministic anyLast(column)
groupBitAnd Bitwise AND groupBitAnd(expr)
groupBitOr Bitwise OR groupBitOr(expr)
groupBitXor Bitwise XOR groupBitXor(expr)
groupBitmap Cardinality groupBitmap(expr)
min(x) Finds the minimum value min(column)
max(x) Finds the maximum value max(x)
argMin(arg, val) Returns the value of arg in the row with the minimum val argMin(c1, c2)
argMax(arg, val) Returns the value of arg in the row with the maximum val argMax(c1, c2)
sum(x) Calculates the sum sum(x)
sumWithOverflow(x) Calculates the sum, returns an error if overflow occurs sumWithOverflow(x)
sumMap(key, value) Used for array types, calculates the sum of values for the same key, returns a tuple of two arrays, the first being the sorted keys and the second being the sum of values for the corresponding keys -
skewPop Calculates skewness skewPop(expr)
skewSamp Calculates sample skewness skewSamp(expr)
kurtPop Calculates kurtosis kurtPop(expr)
kurtSamp Calculates sample kurtosis kurtSamp(expr)
timeSeriesGroupSum(uid, timestamp, value) Calculates the time-series sum for groups by uid, interpolates missing time points linearly before summation -
timeSeriesGroupRateSum(uid, ts, val) Calculates the sum of rate changes for time-series groups by uid -
avg(x) Calculates the average value -
uniq Calculates the approximate count of distinct values uniq(x[, ...])
uniqCombined Calculates the approximate count of distinct values; consumes less memory, offers higher precision than uniq, but slightly worse performance uniqCombined(HLL_precision)(x[, ...]), uniqCombined(x[, ...])
uniqCombined64 64-bit version of uniqCombined, reduces overflow probability -
uniqHLL12 Calculates the approximate count of distinct values, not recommended. Use uniq, uniqCombined instead -
uniqExact Calculates the exact count of distinct values uniqExact(x[, ...])
groupArray(x), groupArray(max_size)(x) Returns an array of x values, array size can be specified by max_size -
groupArrayInsertAt(value, position) Inserts value at a specified position in the array -
groupArrayMovingSum - -
groupArrayMovingAvg - -
groupUniqArray(x), groupUniqArray(max_size)(x) - -
quantile - -
quantileDeterministic - -
quantileExact - -
quantileExactWeighted - -
quantileTiming - -
quantileTimingWeighted - -
quantileTDigest - -
quantileTDigestWeighted - -
median - -
quantiles(level1, level2, …)(x) - -
varSamp(x) - -
varPop(x) - -
stddevSamp(x) - -
stddevPop(x) - -
topK(N)(x) - -
topKWeighted - -
covarSamp(x, y) - -
covarPop(x, y) - -
corr(x, y) - -
categoricalInformationValue - -
simpleLinearRegression - -
stochasticLinearRegression - -
stochasticLogisticRegression - -
groupBitmapAnd - -
groupBitmapOr - -
groupBitmapXor - -