COVAR_SAMP() GROUP BY ...
All functions > GROUP BY > COVAR_SAMP() GROUP BY ...
Returns the sample covariance between two expressions.
Syntax
COVAR_SAMP(expr_y, expr_x) [ FILTER (WHERE condition) ] [ GROUP BY feature [, feature ...] ]
Notes
- Computes the sample covariance (divides by N-1, Bessel's correction)
- NULL values in either expression are excluded from the calculation
- Returns NULL if fewer than 2 non-NULL pairs exist
Examples
FeatureQL
SELECT
f1 := ZIP(ARRAY[1, 2, 3] AS x, ARRAY[2, 4, 6] AS y).TRANSFORM(SELECT COVAR_SAMP(y, x)).UNWRAP_ONE() -- Sample covariance
;Result
| f1 VARCHAR |
|---|
| 2.0 |