Reference Guide > TDV Support for SQL Functions > TDV-Supported Aggregate Functions > AVG
 
AVG
Given a set of numeric values, AVG calculates and returns the average of the input values, as FLOAT, DECIMAL, or NULL.
Syntax
AVG (expression)
Remarks
The expression is a numeric expression.
AVG works only with numeric data types.
If you want to exclude a specific row from the calculation of the average, make any column value in the row NULL.
See About SQL Functions in TDV for an explanation of the DECIMAL(p,s) notation.
The following table lists the input types and their corresponding output types.
Data Type of expression
Output Type
BIGINT, DOUBLE, FLOAT, INTEGER, INTERVAL_DAY, INTERVAL_YEAR, REAL, SMALLINT, TINYINT
Same type as that of the input. For example, if the input is of type TINYINT, the output is also of type TINYINT.
DECIMAL(p,s)
NUMERIC(p,s)
DECIMAL(p,s)
VARCHAR
DECIMAL(p,s)
Runtime exception if expression cannot be converted to a numeric value.
NULL
NULL
Example
SELECT AVG (UnitPrice) Price, ProductID
FROM /shared/examples/ds_inventory/products products
GROUP BY ProductID