regr_count aggregate function (Databricks SQL)

Returns the number of non-null value pairs yExpr, xExpr in the group.

Syntax

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

Arguments

  • yExpr: An numeric expression, the dependent variable.

  • xExpr: An numeric expression, the independent variable.

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

Returns

A BIGINT.

regr_count(yExpr, xExpr) is equivalent to count_if(yExpr IS NOT NULL AND xExpr IS NOT NULL).

If DISTINCT is specified only unique rows are counted.

Examples

> SELECT regr_count(y, x) FROM VALUES (1, 2), (2, 2), (2, 3), (2, 4) AS t(y, x);
  4

> SELECT regr_count(y, x) FROM VALUES (1, 2), (2, NULL), (2, 3), (2, 4) AS t(y, x);
  3

> SELECT regr_count(y, x) FROM VALUES (1, 2), (2, NULL), (NULL, 3), (2, 4) AS t(y, x);
  2