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) |
DECIMAL(p,s) |
|
VARCHAR |
DECIMAL(p,s) |
|
NULL |
NULL |
Example
SELECT AVG (UnitPrice) Price, ProductIDFROM /shared/examples/ds_inventory/products products
GROUP BY ProductID