# Aggregate Functions

<table>
    <thead>
    <tr>
        <th>Function Name</th>
        <th>Description</th>
        <th>Syntax</th>
    </tr>
    </thead>
    <tbody><tr>
        <td>count</td>
        <td>Counts the number of rows or non-NULL values</td>
        <td>count(expr), COUNT(DISTINCT expr), count(), count(*)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-any" target="_blank">any(x)</a></td>
        <td>Returns the first encountered value, result is non-deterministic</td>
        <td>any(column)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#anyheavyx" target="_blank">anyHeavy(x)</a></td>
        <td>Returns frequently occurring values based on the heavy hitters algorithm. Usually non-deterministic results</td>
        <td>anyHeavy(column)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#anylastx" target="_blank">anyLast(x)</a></td>
        <td>Returns the last encountered value, result is non-deterministic</td>
        <td>anyLast(column)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitand" target="_blank">groupBitAnd</a></td>
        <td>Bitwise AND</td>
        <td>groupBitAnd(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitor" target="_blank">groupBitOr</a></td>
        <td>Bitwise OR</td>
        <td>groupBitOr(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitxor" target="_blank">groupBitXor</a></td>
        <td>Bitwise XOR</td>
        <td>groupBitXor(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitmap" target="_blank">groupBitmap</a></td>
        <td>Cardinality</td>
        <td>groupBitmap(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-min" target="_blank">min(x)</a></td>
        <td>Finds the minimum value</td>
        <td>min(column)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-max" target="_blank">max(x)</a></td>
        <td>Finds the maximum value</td>
        <td>max(x)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg-function-argmin" target="_blank">argMin(arg, val)</a></td>
        <td>Returns the value of arg in the row with the minimum val</td>
        <td>argMin(c1, c2)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg-function-argmax" target="_blank">argMax(arg, val)</a></td>
        <td>Returns the value of arg in the row with the maximum val</td>
        <td>argMax(c1, c2)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-sum" target="_blank">sum(x)</a></td>
        <td>Calculates the sum</td>
        <td>sum(x)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#sumwithoverflowx" target="_blank">sumWithOverflow(x)</a></td>
        <td>Calculates the sum, returns an error if overflow occurs</td>
        <td>sumWithOverflow(x)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_functions-summap" target="_blank">sumMap(key, value)</a></td>
        <td>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</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#skewpop" target="_blank">skewPop</a></td>
        <td>Calculates <a href="https://en.wikipedia.org/wiki/Skewness" target="_blank">skewness</a></td>
        <td>skewPop(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#skewsamp" target="_blank">skewSamp</a></td>
        <td>Calculates <a href="https://en.wikipedia.org/wiki/Skewness" target="_blank">sample skewness</a></td>
        <td>skewSamp(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#kurtpop" target="_blank">kurtPop</a></td>
        <td>Calculates <a href="https://en.wikipedia.org/wiki/Kurtosis" target="_blank">kurtosis</a></td>
        <td>kurtPop(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#kurtsamp" target="_blank">kurtSamp</a></td>
        <td>Calculates <a href="https://en.wikipedia.org/wiki/Kurtosis" target="_blank">sample kurtosis</a></td>
        <td>kurtSamp(expr)</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg-function-timeseriesgroupsum" target="_blank">timeSeriesGroupSum(uid, timestamp,   value)</a></td>
        <td>Calculates the time-series sum for groups by uid, interpolates missing time points linearly before summation</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg-function-timeseriesgroupratesum" target="_blank">timeSeriesGroupRateSum(uid, ts,   val)</a></td>
        <td>Calculates the sum of rate changes for time-series groups by uid</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-avg" target="_blank">avg(x)</a></td>
        <td>Calculates the average value</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-uniq" target="_blank">uniq</a></td>
        <td>Calculates the approximate count of distinct values</td>
        <td>uniq(x[, ...])</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-uniqcombined" target="_blank">uniqCombined</a></td>
        <td>Calculates the approximate count of distinct values; consumes less memory, offers higher precision than uniq, but slightly worse performance</td>
        <td>uniqCombined(HLL_precision)(x[, ...]), uniqCombined(x[,  ...])</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-uniqcombined64" target="_blank">uniqCombined64</a></td>
        <td>64-bit version of uniqCombined, reduces overflow probability</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-uniqhll12" target="_blank">uniqHLL12</a></td>
        <td>Calculates the approximate count of distinct values, not recommended. Use uniq, uniqCombined instead</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-uniqexact" target="_blank">uniqExact</a></td>
        <td>Calculates the exact count of distinct values</td>
        <td>uniqExact(x[, ...])</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-grouparray" target="_blank">groupArray(x),   groupArray(max_size)(x)</a></td>
        <td>Returns an array of x values, array size can be specified by max_size</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#grouparrayinsertatvalue-position" target="_blank">groupArrayInsertAt(value, position)</a></td>
        <td>Inserts value at a specified position in the array</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-grouparraymovingsum" target="_blank">groupArrayMovingSum</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_function-grouparraymovingavg" target="_blank">groupArrayMovingAvg</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupuniqarrayx-groupuniqarraymax-sizex" target="_blank">groupUniqArray(x),   groupUniqArray(max_size)(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantile" target="_blank">quantile</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantiledeterministic" target="_blank">quantileDeterministic</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantileexact" target="_blank">quantileExact</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantileexactweighted" target="_blank">quantileExactWeighted</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantiletiming" target="_blank">quantileTiming</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantiletimingweighted" target="_blank">quantileTimingWeighted</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantiletdigest" target="_blank">quantileTDigest</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantiletdigestweighted" target="_blank">quantileTDigestWeighted</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#median" target="_blank">median</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#quantiles" target="_blank">quantiles(level1, level2, …)(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#varsampx" target="_blank">varSamp(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#varpopx" target="_blank">varPop(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#stddevsampx" target="_blank">stddevSamp(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#stddevpopx" target="_blank">stddevPop(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#topknx" target="_blank">topK(N)(x)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#topkweighted" target="_blank">topKWeighted</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#covarsampx-y" target="_blank">covarSamp(x, y)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#covarpopx-y" target="_blank">covarPop(x, y)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#corrx-y" target="_blank">corr(x, y)</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#categoricalinformationvalue" target="_blank">categoricalInformationValue</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#simplelinearregression" target="_blank">simpleLinearRegression</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_functions-stochasticlinearregression" target="_blank">stochasticLinearRegression</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#agg_functions-stochasticlogisticregression" target="_blank">stochasticLogisticRegression</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitmapand" target="_blank">groupBitmapAnd</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitmapor" target="_blank">groupBitmapOr</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    <tr>
        <td><a href="https://clickhouse.tech/docs/en/query_language/agg_functions/reference/#groupbitmapxor" target="_blank">groupBitmapXor</a></td>
        <td>-</td>
        <td>-</td>
    </tr>
    </tbody></table>