Skip to main content

Aggregate functions

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

COUNT

Counts rows or non-null values. Use COUNT(1) for total row counts and COUNT(column) for counting non-null values.

APPROX_COUNT_DISTINCT

Returns the approximate number of distinct values in a column. Faster and cheaper than COUNT(DISTINCT ...), and returns exact results for low-cardinality columns. Use this instead of COUNT(DISTINCT ...) unless your query requires a guaranteed exact count.
APPROX_COUNT_DISTINCT is the recommended way to count unique values in most queries. It produces exact results when the number of distinct values is small and near-exact results at scale—while using significantly fewer resources than COUNT(DISTINCT ...).

SUM

Returns the sum of values.

AVG

Returns the average of values.

MIN / MAX

Returns the minimum or maximum value.

STDDEV_POP / STDDEV_SAMP

Returns population or sample standard deviation.

VAR_POP / VAR_SAMP

Returns population or sample variance.

ARRAY_AGG

Aggregates values into an array.

STRING_AGG

Concatenates values into a delimited string.

PERCENTILE_CONT

Returns a percentile value using continuous distribution.

Window Functions

Ranking and analytics

Numeric Functions

Math and rounding

All Functions

Browse all function categories

SELECT

GROUP BY and HAVING clauses