SQLite - Highest 60 second average in a time series?
I'm trying to find the highest 60 second average over an hours worth of data in sqlite.
Here's what I got so far:
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
Each tick represents a second. "Watts" is the field that I'm trying to find the highest average. WorkoutSu开发者_StackOverflow社区mmaryID just represents a workout.
The code above says too many parenthesis in sqlite. Does anyone know how to get the highest 60 second average over a time series?
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
You have indeed got too many closing parenthesis in your statement. You are missing the opening parenthesis around the sub-query:
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
精彩评论