.-ALL------. >>-AVG--(----+----------+--expression--)----------------------->< '-DISTINCT-'
The AVG function returns the average of a set of numbers.
The argument values must be numbers and their sum must be within the range of the data type of the result. The result can be null.
The data type of the result is the same as the data type of the argument values, except that:
If the data type of the argument values is decimal with precision p and scale s, the precision of the result is 31 and the scale is 31-p+s.
The function is applied to the set of values derived from the argument values by the elimination of null values. If DISTINCT is specified, duplicate values are eliminated.
If the function is applied to an empty set, the result is a null value. Otherwise, the result is the average value of the set.
If the type of the result is integer, the fractional part of the average is lost.
Examples:
SELECT AVG(PRSTAFF) INTO :AVERAGE FROM PROJECT WHERE DEPTNO = 'D11'
Results in AVERAGE being set to 4.25 (that is 17/4) when using the sample table.
SELECT AVG(DISTINCT PRSTAFF) INTO :ANY_CALC FROM PROJECT WHERE DEPTNO = 'D11'
Results in ANY_CALC being set to 4.66 (that is 14/3) when using the sample table.