Results 1 to 4 of 4
  1. #1
    DBA-Meister is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    22

    Question Grouping Question

    I have a Scores table with 3 fields: ID, Week-Number, and Score.


    This is for a double-elimination dart league, so each week can have any number of rows per ID, although it is rare for one person to have more than 7 scores in any one week.

    We have a table for players that contains player name and player ID.

    We want to calculate a handicap for each person as follows:
    1. find the average of the highest scores for each person using only the 3 highest scores for that person (if he/she had 3 scores - might only be 2).
    2. Calculate the average of the 20 most recent averages for each player.
    3. Produce a report with Player Name and the calculated average.


    I have two questions:
    1. Can this be done in one single query or do we need to have queries calling queries?
    2. Even if it can be done, does this make sense or should we use individual queries?

    Thanks to anyone who can help.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    1. pull top 3 records for each person - review http://allenbrowne.com/subquery-01.html#TopN

    2. would do you mean by '20 most recent' - last 20 weeks?

    3. okay, get the queries built first

    Probably queries calling queries (or nested).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DBA-Meister is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2012
    Posts
    22
    I wasn't clear in the post. Each week a player shows up, he or she plays until they have lost 2 games. They will therefore have 2 or more entries (rows in the scores table) for each week they play. I want to find the 20 most recent weeks played for each player, find the average of their 3 highest games for each of those weeks played, then calculate the average of those averages for each players most recent 20 weeks. If a player hasn't yet played 20 weeks, I want to use all the weeks he or she has played. The scores table has 3 columns: Week_Nmbr, Player_id, Score.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Sounds complicated. Never tried anything like this.

    Maybe:

    1. query that pulls TOP 3 for each week for each player

    2. use that query in an aggregate query to calc the average

    3. use that query in another query to pull TOP 20 weeks for each player

    4. use that query in an aggregate query to calc average
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. SQL noob question, grouping results.
    By spiroom in forum Queries
    Replies: 2
    Last Post: 10-18-2015, 11:05 AM
  2. Grouping AVG, want to ignore calculation question.
    By McArthurGDM in forum Programming
    Replies: 5
    Last Post: 06-21-2015, 12:53 PM
  3. Replies: 1
    Last Post: 02-13-2015, 06:26 AM
  4. Grouping Question
    By McArthurGDM in forum Queries
    Replies: 11
    Last Post: 07-16-2014, 10:03 AM
  5. Sorting\Grouping question from a newb
    By jcampbell in forum Reports
    Replies: 1
    Last Post: 02-25-2013, 03:28 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums