Aggregate Functions

An aggregate function performs a calculation operation on a set of input values and returns a value. For example, the COUNT function counts the number of rows retrieved by an SQL statement. Table 1 lists aggregate functions.

Sample data: Table T1
|score|
|81   |
|100  |
|60   |
|95   |
|86   |

Common Aggregate Functions

Table 1 Common aggregate functions

Function

Return Data Type

Description

COUNT(*)

BIGINT

Return count of tuples.

COUNT([ ALL ] expression...

BIGINT

Returns the number of input rows for which the expression is not NULL. Use DISTINCT for a unique instance of each value.

AVG(numeric)

DOUBLE

Return average (arithmetic mean) of all input values.

SUM(numeric)

DOUBLE

Return the sum of all input numerical values.

MAX(value)

DOUBLE

Return the maximum value of all input values.

MIN(value)

DOUBLE

Return the minimum value of all input values.

STDDEV_POP(value)

DOUBLE

Return the population standard deviation of all numeric fields of all input values.

STDDEV_SAMP(value)

DOUBLE

Return the sample standard deviation of all numeric fields of all input values.

VAR_POP(value)

DOUBLE

Return the population variance (square of population standard deviation) of numeral fields of all input values.

VAR_SAMP(value)

DOUBLE

Return the sample variance (square of the sample standard deviation) of numeric fields of all input values.

Example