我有一个SQLite表:
CREATE TABLE `Readings` ( `ID` TEXT, `Reading` TEXT, `Date` TEXT )
每个日期我都有ID标识的不同传感器的真实读数。是否可以获得具有相同ID但不同日期的传感器读数之间差异的结果表?
答案 0 :(得分:0)
假设您使用的是proper date format,则可以使用correlated subquery查找相应的上一个值:
SELECT ID,
Date,
Reading - (SELECT Reading
FROM Readings AS R2
WHERE R2.ID = Readings.ID
AND R2.Date < Readings.Date
ORDER BY Date DESC
LIMIT 1
) AS Difference
FROM Readings;