我试图找到sqlite中一小时数据的最高60秒平均值。
这是我到目前为止所得到的:
SELECT MAX(SELECT AVG(watts)
FROM tblworkoutdata d2
WHERE d2.workoutsummaryid = d1.workoutsummaryid
AND d2.ticks BETWEEN d1.ticks AND d1.ticks + 60)) AS theMax
FROM tblworkoutdata d1
WHERE workoutsummaryid = 198
每个刻度线代表一秒钟。 “Watts”是我试图找到最高平均值的领域。 WorkoutSummaryID只代表锻炼。
上面的代码在sqlite中说太多括号。有谁知道如何在一个时间序列中获得最高的60秒平均值?
答案 0 :(得分:4)
SELECT MAX((SELECT AVG(watts)
FROM tblworkoutdata d2
WHERE d2.workoutsummaryid = d1.workoutsummaryid
AND d2.ticks BETWEEN d1.ticks AND d1.ticks + 60)) AS theMax
FROM tblworkoutdata d1
WHERE workoutsummaryid = 198
答案 1 :(得分:2)
你的陈述中确实有太多的右括号。您缺少子查询周围的左括号:
SELECT MAX((SELECT AVG(watts)
FROM tblworkoutdata d2
WHERE d2.workoutsummaryid = d1.workoutsummaryid
AND d2.ticks BETWEEN d1.ticks AND d1.ticks + 60)) AS theMax
FROM tblworkoutdata d1
WHERE workoutsummaryid = 198