REGR_SLOPE()
Overview
The REGR_SLOPE()
aggregate function calculates the slope of the regression line for a linear relationship between a dependent variable (y) and an independent variable (x). The slope represents the rate of change in y
for every unit increase in x
. This function is used in regression analysis to quantify the strength and direction of a linear relationship.
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_SLOPE()
function to calculate the slope of the regression line for valid pairs of rating
and length
:
By running the above code, we will get the following output: