[thelist] help with SQL query

danielEthan daniel at ionize.net
Wed Jul 31 10:55:01 CDT 2002


>There is a field for the date [ActivityDate] , number of steps
>[Steps], Week Number [ProgramWeek], user Id [UserID]. What I need is to get
>the average number of weekly steps for an individual user.
>
>Working with an unknown number of weeks is it possible to get the average
>for each week then get the avg of all weeks combined in a select statement?

Hope I can help. But I do have a couple of questions: For each record, you are entering the steps for the week, right? Therefore, all you need is the average steps where the userID are all the same. The number of weeks shouldn't matter at all. This should give you what you want:

SELECT UserID, Avg(Steps) AS WeeklyAvg
>From myDb
GROUP BY UserID
ORDER BY UserID;

Hope this is what you're looking for.

=D



More information about the thelist mailing list