Categories:
Aggregate Functions (Linear Regression) , Window Functions

REGR_AVGY

Returns the average of the dependent variable for non-null pairs in a group, where x is the independent variable and y is the dependent variable.

Syntax

REGR_AVGY(y, x)

Usage Notes

  • DISTINCT is not supported for this function.
  • In order for a row to be included in the average, BOTH the x and y values must be non-NULL.

Examples

create or replace table aggr(k int, v decimal(10,2), v2 decimal(10, 2));
insert into aggr values(1, 10, null);
insert into aggr values(2, 10, 11), (2, 20, 22), (2, 25,null), (2, 30, 35);
select k, regr_avgy(v, v2) from aggr group by k;

---+------------------+
 k | regr_avgy(v, v2) |
---+------------------+
 1 | [NULL]           |
 2 | 20               |
---+------------------+