REGR_SLOPE() GROUP BY ...

All functions > GROUP BY > REGR_SLOPE() GROUP BY ...

Returns the slope of the linear regression line fitted to (x, y) pairs.

Syntax

REGR_SLOPE(expr_y, expr_x)
 [ FILTER (WHERE condition) ]
  [ GROUP BY feature [, feature ...] ]

Notes

  • Equivalent to COVAR_POP(y, x) / VAR_POP(x)
  • NULL values in either expression are excluded from the calculation
  • Returns NULL if VAR_POP(x) is zero or fewer than 2 non-NULL pairs exist

Examples

FeatureQL
SELECT
    -- Regression slope for y = 2x
    f1 := ZIP(ARRAY(1, 2, 3) AS x, ARRAY(2, 4, 6) AS y).TRANSFORM(
        SELECT REGR_SLOPE(y, x)
    ).UNWRAP_ONE()
;
Result
f1 VARCHAR
2.0

Last update at: 2026/06/20 10:08:10