covar_samp aggregate function

Returns the sample covariance of number pairs in a group.

Syntax

covar_samp ( [ALL | DISTINCT] expr1, expr2 ) [FILTER ( WHERE cond ) ]

Arguments

  • expr1: An expression that evaluates to a numeric.

  • expr2: An expression that evaluates to a numeric.

  • cond: An optional boolean expression filtering the rows used for aggregation.

Returns

A DOUBLE.

If DISTINCT is specified the function operates only on a unique set of expr1, expr2 pairs.

Examples

> SELECT covar_samp(c1, c2) FROM VALUES (1,1), (2,2), (2, 2), (3,3) AS tab(c1, c2);
 0.6666666666666666
> SELECT covar_samp(DISTINCT c1, c2) FROM VALUES (1,1), (2,2), (2, 2), (3,3) AS tab(c1, c2);
 1.0