SELECT list, or in a subquery (see examples below).
When used with non-aggregate expression(s), a GROUP BY operation is needed on the non-aggregated expression(s). When using GROUP BY, each aggregate result is computed over the rows matching that GROUP BY column value (see examples below).
The following table shows the available aggregate functions:
Note that all the functions other than COUNT return NULL when no rows are selected (COUNT returns zero).
Notes:
-
AVG(): When the column data type is integral orDECIMAL, the return value isDECIMAL. Otherwise, the return value isDOUBLE. -
When the column data type is an approximate numeric data type (
DOUBLE,FLOAT,REAL), the return value isDOUBLE. -
COUNT(input_column): When using theCOUNT()function over a specific column/expression, only the non-NULL values are counted. E.g, if the table has 4 rows and the column values are (1,2,NULL,4), theCOUNT()of this column returns 3. -
Note that in the case of
COUNT(*), all rows are counted, including rows with only NULLs in their column values. -
COUNT (DISTINCT): TheDISTINCTcan come only once in a given select statement. -
SUM(): The returned value depends on the input data type: 6.1. Whenintegral_typeorDECIMAL, the returned value isDECIMAL6.2. WhenDOUBLE, the returned value isDOUBLE -
STDDEV(): The return value depends on the column data type: 7.1. Whenintegral_typeorDECIMALthe return value isDECIMAL7.2. WhenDOUBLE, the return value isDOUBLE.