Skip to navigation

Aggregate Functions

View as Markdown

Aggregate functions compute a single result from a group of rows.

You can use the DISTINCT keyword with any aggregation function, such as COUNT(DISTINCT col).

Aggregate Functions

FunctionSyntaxPurpose
ANY_VALUEANY_VALUE(col)Returns an arbitrary, non-NULL, value from the input column.
The function gives preference to any non-NULL values in the column and returns NULL only if all rows in the input column are NULL.
The ANY_VALUE function is explicitly undefined if you use it for window aggregation and the function generates an error.
APPROX_COUNT_DISTINCTAPPROX_COUNT_DISTINCT(col)Approximate distinct count by using hyper-log-log (95% confidence interval that the value is within 4.5%)
APPROX_SUMAPPROX_SUM(col)Allows the aggregation engine to use a faster, non-deterministic, ordering to summate floating-point columns. This summation might lead to minute differences in the result on the order of the machine epsilon. For other column types, the aggregation engine uses the standard SUM algorithm.
AVGAVG(col)Average, or arithmetic mean, over the set
CORRELATIONCORRELATION(col1,col2)Sample correlation
CORRCORR(col1,col2)Alias for CORRELATION
CORRELATIONPCORRELATIONP(col1,col2)Population correlation
COUNTCOUNT(col)Number of rows in the set where values in col are not null
COUNTCOUNT(*)Total number of rows in the table
COVARIANCECOVARIANCE(col1,col2)Sample covariance
COVAR_SAMPCOVAR_SAMP(col1, col2)Alias for COVARIANCE
COVARIANCEPCOVARIANCEP(col1,col2)Population covariance
COVAR_POPCOVAR_POP(col1, col2)Alias for COVARIANCEP
MAXMAX(col)Maximum value in the given column
MINMIN(col)Minimum value in the given column
STDEVPSTDEVP(col)Population standard deviation
STDDEV_POPSTDDEV_POP(col)Alias for STDEVP
STDEVSTDEV(col)Sample standard deviation
STDDEVSTDDEV(col)Alias for STDEV
STDDEV_SAMPSTDDEV_SAMP(col)Alias for STDEV
SUMSUM(col)Sum over the set
VARIANCEVARIANCE(col)Sample variance
VAR_SAMPVAR_SAMP(col)Alias for VARIANCE
VARIANCEPVARIANCEP(col)Population variance
VAR_POPVAR_POP(col)Alias for VARIANCEP
PRODUCTPRODUCT(col)Product over the set
SKEWSKEW(col)The sample over the set
SWEPSWEWP(col)The population over the set
KURTOSISKURTOSIS(col)The sample over the set
KURTOSISPKURTOSISP(col)The population over the set

Sorted Aggregate Functions

Math Functions and Operators

Query Ocient