AVG
Computes the arithmetic mean of the values in the argument. Null values are ignored.
SQL syntax
AVG ([ALL | DISTINCT] Expression) [OVER ([AnalyticClause])]Parameters
AVG has the following parameters:
| Parameter | Description |
|---|---|
|
|
Can be any numeric data type or any nonnumeric data type that can be implicitly converted to a numeric data type. |
|
|
Includes duplicate rows in the argument of an aggregate function. If neither |
|
|
Eliminates duplicate column values from the argument of an aggregate function. |
|
|
If specified, indicates aggregate analytic function. For more information on analytic functions, see "Analytic Functions". |
Description
-
If
AVGis computed over an empty table in whichGROUP BYis not used, thenAVGreturnsNULL. -
If
AVGis computed over an empty group or an empty grouped table (GROUP BYis used),AVGreturns nothing. -
AVGis evaluated asSUM/COUNT. The result data type is derived using the rule that is applied for theDIVoperator. -
If you do not specify the
AnalyticClausein your query, thenAVGacts as an aggregate function. -
If you specify
DISTINCTand theAnalyticClause, then you can only specify theQueryPartitionClause. TheOrderByClauseandWindowingClauseare not allowed.
Examples
Calculate the average salary for employees in the HR schema. Use CAST to cast the average as the data type of the column:
Command> SELECT CAST(AVG (salary) AS NUMBER (8,2)) FROM employees; < 6461.68 >