16.20 - Example: Returning the Slope of the Regression Line for NbrSold and SalesPrice - Teradata Vantage NewSQL Engine

Teradata Vantageā„¢ SQL Functions, Expressions, and Predicates

prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1145-162K

This example uses the data from the HomeSales table.

SalesPrice NbrSold Area
160000 126 358711030
180000 103 358711030
200000 82 358711030
220000 75 358711030
240000 82 358711030
260000 40 358711030
280000 20 358711030

The following query returns the slope of the regression line for NbrSold and SalesPrice in the range of 160000 to 280000 in the 358711030 area.

   SELECT CAST (REGR_SLOPE(NbrSold,SalesPrice) AS FLOAT)  
   FROM HomeSales
   WHERE area = 358711030 
   AND SalesPrice BETWEEN 160000 AND 280000;

Here is the result:

   REGR_SLOPE(NbrSold,SalesPrice)
   ------------------------------
           -7.92857142857143E-004