VAR_POP or VARIANCE or VAR

The VAR_POP function returns the biased variance (/n) of a set of numbers.

Read syntax diagramSkip visual syntax diagram
                    .-ALL------.                          
>>-+-VAR_POP--+--(--+----------+--numeric-expression--)--------><
   +-VARIANCE-+     '-DISTINCT-'                          
   '-VAR------'                                           

The formula used to calculate the biased variance is:
   VAR_POP = SUM(X**2)/COUNT(X) - (SUM(X)/COUNT(X))**2
numeric-expression
The argument values must be any built-in numeric data type.

If the argument is DECFLOAT(n), the result of the function is DECFLOAT(34). Otherwise, the data type of the result is double-precision floating point.

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.

The result can be null. If the function is applied to the empty set, the result is a null value. Otherwise, the result is the variance of the values in the set.

The order in which the values are added is undefined, but every intermediate result must be within the range of the result data type.

Notes

Start of changeResults involving DECFLOAT special values: If the data type of the argument is decimal floating-point and a special value of sNaN or -sNaN, or both +Infinity and -Infinity are included in the aggregation, an error or warning is returned. Otherwise, if +NaN or -NaN is found, the result is +NaN or -NaN. If +Infinity or -Infinity is found, the result is +Infinity or -Infinity.End of change

Syntax alternatives: VAR_POP should be used for conformance to the SQL 2003 standard.

Example

  • Using the EMPLOYEE table, set the host variable VARNCE (double-precision floating point) to the variance of the salaries for those employees in department A00.
         SELECT VAR_POP(SALARY)
           INTO :VARNCE
           FROM EMPLOYEE
           WHERE WORKDEPT = 'A00';
    Results in VARNCE being set to approximately 94 915 000.