Start of change

COVAR_POP or COVARIANCE or COVAR

The COVAR_POP function returns the population covariance of a set of number pairs.

Read syntax diagramSkip visual syntax diagramCOVAR_POPCOVARIANCECOVAR( expression-1, expression-2)

The schema is SYSIBM.

The argument values must each be the value of any built-in numeric data type.

If an argument is DECFLOAT(n), the result of the function is DECFLOAT(34). Otherwise, the result of the function is double precision floating-point. The result can be null.

The function is applied to the set of (expression-1, expression-2) pairs that are derived from the argument values by the elimination of all pairs for which either expression-1 or expression-2 is null.

If the function is applied to an empty set, the result is a null value. Otherwise, the result is the population covariance of the value pairs in the set. The result is equivalent to the following output:

  1. Let avgexp1 be the result of AVG(expression-1) and let avgexp2 be the result of AVG(expression-2).
  2. The result of COVARIANCE(expression-1,expression-2) is AVG( (expression-1 - avgexp1) * (expression-2 - avgexp2))

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

Example

Using sample table DSN8C10.EMP, set the host variable COVARNCE (double-precision floating-point) to the population covariance between the salary and the bonus for those employees in department (WORKDEPT) 'A00'.

   SELECT COVARIANCE(SALARY, BONUS)
    INTO :covarnce
     FROM DSN8C10.EMP
     WHERE WORKDEPT = 'A00'

The value of COVARNCE is set to 1743000.

Notes

Syntax alternatives:
COVAR_POP should be used for conformance to the SQL standard.
End of change