regr_sxy aggregate function

Returns the sum of products of yExpr and xExpr calculated from values of a group where xExpr and yExpr are NOT NULL.

Since: Databricks Runtime 11.0


regr_sxy( [ALL | DISTINCT] yExpr, xExpr) [FILTER ( WHERE cond ) ]


  • yExpr: A numeric expression, the dependent variable.

  • xExpr: A numeric expression, the independent variable.

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


The result type is a DOUBLE.

Any nulls within the group are ignored. If a group is empty or consists only of nulls, the result is NULL.

If DISTINCT is specified, the result is computed after duplicates are removed.

regr_sxy(y, x) is a synonym for regr_count(y, x) * covar_pop(y, x).


> SELECT regr_sxy(y, x) FROM VALUES (1, 2), (2, 3), (2, 3), (null, 4), (4, null) AS T(y, x);