66.Oracle数据库SQL开发之 高级查询——使用线性回归函数
线性回归函数可以用普通最小平方回归曲线拟合一组数值对。线性回归函数可用于聚合、串口或报表函数。
如下图1:
例如:
store@PDB1> selectprd_type_id,regr_avgx(amount,month) as avgx,
regr_avgy(amount,month) as avgy,
regr_count(amount,month) as count,
regr_intercept(amount,month) as inter,
regr_r2(amount,month) as r2,
regr_slope(amount,month) as slope,
regr_sxx(amount,month) as sxx,
regr_sxy(amount,month) as sxy,
regr_syy(amount,month) as syy
fromall_sales
whereyear=2003 group by prd_type_id;
PRD_TYPE_ID AVGX AVGY COUNT INTER R2 SLOPE SXX SXY
----------- ---------- -------------------- ---------- ---------- ---------- ---------- ----------
SYY
----------
1 6.5 12570.5811 72 13318.4543 .003746289-115.05741 858 -98719.26
3031902717
2 6.5 2588.62806 72 2608.11268 .0000508 -2.997634 858 -2571.97
151767392
5 0
4 6.5 5593.76611 72 2043.47164 .128930297546.199149 858 468638.87
1985337488
3 6.5 6642.65153 72 2154.23119 .126338815690.526206 858 592471.485
3238253324