An AVG of a DECIMAL or INTEGER value may overflow if the individual values are large or if there is a large number of values.
If this occurs, change the AVG call to include a CAST function that converts the DECIMAL or INTEGER values to REAL as shown in the following example:
AVG(CAST(value AS REAL) )
Casting the values as REAL before averaging causes a slight loss in precision.
The type of the result is REAL in either case, so the only effect of the CAST is to accept a slight loss of precision where a result may not otherwise be available at all.
If x is an integer, AVG does not display a fractional value. For a fractional value, cast the value as DECIMAL. For example:
CAST(AVG(value) AS DECIMAL(9,2))