An AVG of a DECIMAL or INTEGER value may overflow if the individual values are very 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 might not otherwise be available at all.
If x is an integer, AVG does not display a fractional value. A fractional value may be obtained by casting the value as DECIMAL, for example the following CAST to DECIMAL.
CAST(AVG(value) AS DECIMAL(9,2))