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

# `regr_avgy` 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 mean of `yExpr` calculated from values of a group where `xExpr` and `yExpr` are `NOT NULL`.

## Syntax

```
regr_avgy( [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

The result type depends on the type of `yExpr`:

* `DECIMAL(p, s)`: The result type is a` DECIMAL(p + 4, s + 4)`. If the maximum precision for `DECIMAL` is reached the increase in scale will be limited to avoid loss of significant digits.
* Otherwise, the result 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 average is computed after duplicates have been removed.

`regr_avgy(y, x)` is a synonym for `avg(y) FILTER(WHERE x IS NOT NULL AND y IS NOT NULL)`.

## Examples

```sql
> SELECT regr_avgy(y, x) FROM VALUES (1, 2), (2, 3), (2, 3), (null, 4), (4, null) AS T(y, x);
  1.6666666666666667
```

## Related

* [`avg` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/avg.md)
* [`regr_avgy` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_avgy.md#)
* [`regr_count` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_count.md)
* [`regr_sxy` aggregate function](https://docs.databricks.com/aws/en/sql/language-manual/functions/regr_sxy.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)
* [Window functions](https://docs.databricks.com/aws/en/sql/language-manual/sql-ref-window-functions.md)
