SQLite-时间序列中的最高60秒平均值?

问题描述

| 我正在尝试在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秒平均值?     

解决方法

        您的声明中确实包含太多右括号。您缺少子查询周围的左括号:
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
    ,        
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