REGR_AVGX()
Overview
The REGR_AVGX()
aggregate function calculates the average of the independent variable (x) for non-null pairs of dependent (y) and independent (x) variables. This function is commonly used in linear regression analysis to compute the mean of the independent variable where both variables are not null.
Syntax
The syntax for this function is as follows:
Parameters
y
: variable being predictedx
: variable used for prediction
Example
For the needs of this section, we’re going to use a simplified version of the film
table from the Pagila database, containing only the title
, length
and rating
columns. The complete schema for the film
table can be found on the
Pagila database website.
The query below uses the REGR_AVGX()
function to calculate the average rating for films where both length
and rating
are not null:
By executing the above code, we will get the following output: