Aggregate

Aggregate#

Aggregate functions perform a calculation on a set of values and return a single value. Apart from COUNT(*), they ignore null values.

Function

Description

APPROX_COUNT_DISTINCT

Returns the number of rows in a data set that have distinct non-NULL values, where the return value is within a specified range of error tolerance. APPROX_COUNT_DISTINCT can return a value between 0 and 247.

AVG

Returns the average of the values in a group. Null values are ignored.

CHECKSUM_AGG

Returns the checksum of the values in a group. Null values are ignored. Can be followed by the OVER clause.

COUNT

Returns the number of items in a group. COUNT works like the COUNT_BIG function. The only difference between the two functions is their return values. COUNT always returns an int data type value. COUNT_BIG always returns a bigint data type value.

COUNT_BIG

Returns the number of items in a group. COUNT_BIG works like the COUNT function. The only difference between the two functions is their return values. COUNT_BIG always returns a bigint data type value. COUNT always returns an int data type value.

GROUPING

Indicates whether a specified column expression in a GROUP BY list is aggregated or not. GROUPING returns 1 for aggregated or 0 for not aggregated in the result set. GROUPING can be used only in the SELECT <select> list, HAVING, and ORDER BY clauses when GROUP BY is specified.

GROUPING_ID

Is a function that computes the level of grouping. GROUPING_ID can be used only in the SELECT <select> list, HAVING, or ORDER BY clauses when GROUP BY is specified.

KURTOSIS

Returns the kurtosis of the values in the expression.

MAX

Returns the maximum value in the expression.

MIN

Returns the minimum value in the expression. May be followed by the OVER clause.

SKEWNESS

Returns the skewness of the values in the expression.

STDEV

Returns the statistical standard deviation of all values in the specified expression.

STDEVP

Returns the statistical standard deviation for the population for all values in the specified expression.

STRING_AGG

Concatenates the values of string expressions and places separator values between them.

SUM

Returns the sum of all the values, or only the DISTINCT values, in the expression. SUM can be used with numeric columns only. Null values are ignored.

VAR

Returns the statistical variance of all values in the specified expression. May be followed by the OVER clause.

VARP

Returns the statistical variance for the population for all values in the specified expression.