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
AVG
is computed over an empty table in whichGROUP BY
is not used, thenAVG
returnsNULL
. -
If
AVG
is computed over an empty group or an empty grouped table (GROUP BY
is used),AVG
returns nothing. -
AVG
is evaluated asSUM
/COUNT
. The result data type is derived using the rule that is applied for theDIV
operator. -
If you do not specify the
AnalyticClause
in your query, thenAVG
acts as an aggregate function. -
If you specify
DISTINCT
and theAnalyticClause
, then you can only specify theQueryPartitionClause
. TheOrderByClause
andWindowingClause
are 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 >