以下查询未返回我对slope
和的预期/期望结果intercept
。我终于意识到这一点,slope
并且intercept
在我的锚查询中被类型转换为整数,并通过递归保持整数。
WITH RECURSIVE t AS (
SELECT id parentId, idPublic parentIdPublic, name parentName,
slope parentSlope, intercept parentIntercept,
id, idPublic, name, type, 1 slope, 0 intercept, value
FROM measurements
WHERE id IN (414,415,416,417,491)
UNION ALL
SELECT t.parentId, t.parentIdPublic, t.parentName,
t.parentSlope, t.parentIntercept,
m.id, m.idPublic, m.name, m.type,
t.slope*pchm.sign*m.slope slope,
t.intercept+t.slope*pchm.sign*m.intercept intercept, m.value
FROM t
INNER JOIN subpoints sp ON sp.measurementId=t.id
INNER JOIN measurements m ON m.id=sp.measurementId
)
SELECT slope, intercept FROM t;
slope
并且intercept
需要能够存储差异很大的值,准确度并不重要,所以我觉得FLOAT
最好。我的架构slope
和intercept
如图所示:
`slope` FLOAT NOT NULL DEFAULT 1,
`intercept` FLOAT NOT NULL DEFAULT 0,
作为 hack 解决方案,我将锚查询更改为:
SELECT id parentId, ..., 1.0 slope, 0.0 intercept, value
我认为正确的解决方案是将这两个值类型化为 a FLOAT
,但文档似乎不允许。我可以这样做DECIMAL
,但是,我有一个问题,slope
并且intercept
可能是一个广泛的价值观。
我可以投slope
吗?如果不是,最好的解决方案是什么?intercept
FLOAT