---
title: regr_count aggregate function
description: Learn the syntax of the regr\_count aggregate function of the SQL language in Databricks SQL and Databricks Runtime.
canonical_url: https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_count
---

# `regr_count` aggregate function

**Applies to:** ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks SQL ![check marked yes](https://docs.databricks.com/aws/en/images/icons/check.png) Databricks Runtime 11.3 LTS and above

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

## Syntax

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

This function can also be invoked as a [window function](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md) using the `OVER` clause.

## Arguments

* `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.

## 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

```sql
> 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
```

## Related

* [`avg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/avg.md)
* [`count` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/count.md)
* [`count_if` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/count_if.md)
* [`min` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/min.md)
* [`max` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/max.md)
* [`regr_avgx` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_avgx.md)
* [`regr_avgy` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_avgy.md)
* [`regr_sxx` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_sxx.md)
* [`regr_sxy` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_sxy.md)
* [`regr_syy` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_syy.md)
* [`sum` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/sum.md)
* [Window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md)
