[thelist] help with SQL query

danielEthan daniel at ionize.net
Wed Jul 31 16:53:01 CDT 2002


>I need the average steps per week not a total average for one user,
>
>so user 777 has been at it for say 6 weeks, I need the average # of steps he
>takes in a one week period. The statement below returns each weeks average.
>I can use it as a subquery to get the one average from those weeks?
>
>SELECT avg(steps) FROM tblRecordSteps where UserID='777' GROUP BY
>ProgramWeek
>

When then all you need to do is add another GROUP BY:

SELECT avg(steps) FROM tblRecordSteps where UserID='777'
GROUP BY UserID, ProgramWeek

This is contingent on ProgramWeek being the same for each
week, e.g. using a 1 or the same date for the week. Otherwise
you'll have to use BETWEEN on the ProgramWeek.

=D




More information about the thelist mailing list