我试图找到一个数据集的斜率,它以 DATETIME 作为 x 轴,在 y 轴上有一个数字。
我尝试了多种方法,当我将数据插入 Excel 时,没有任何东西可以匹配线的斜率,它偏离了多个数量级。
这就是我现在所拥有的,但它给了我一个 -1.13e-13 而不是 -0.008 的斜率
SELECT (SUM((x-xBar)*(y-yBar)))/(SUM((x-xBar))*SUM((x-xBar)))) as slope
from (select unix_timestamp(date) as x,
(select avg(unix_timestamp(date)) from datatable) as xBar,
value as y,
(select avg(value) from datatable) as yBar from datatable) as d;
任何帮助将不胜感激,谢谢。
更新:
我也试过
SELECT effortId,
( COUNT(*)*SUM(unix_timestamp(date)*value) -SUM(unix_timestamp(date))*SUM(value) ) /
(COUNT(*)*SUM(unix_timestamp(date)^2)-SUM(unix_timestamp(date))^2) AS Slope
FROM datatable;
并得到一个完全不同的答案(-0.0019),这更准确吗?有人知道吗?