AVG Function
Description
The AVG function calculates the arithmetic mean of a specified expression across a set of data. When the DISTINCT keyword is specified, the average is calculated on deduplicated values.
Parameters
expr: A numeric expression of typeTINYINT,SMALLINT,INT,BIGINT,FLOAT,DOUBLE, orDECIMAL.
Return Type
- For
DECIMALtype expressions, theAVGfunction returns aDECIMALtype result. The return value's precision and scale may increase to accommodate the calculation result. - For other numeric type expressions, the
AVGfunction returns aDOUBLEtype result.
Notes
- During calculation,
NULLvalues are ignored and do not participate in the average calculation.
Examples
- Calculate the average of a numeric column (excluding
NULLvalues):
- Calculate the average of a numeric column with deduplication:
- Use the FILTER clause for conditional average calculation:
- Combine FILTER clause and DISTINCT for deduplicated conditional average:
