Results 1 to 14 of 14
  1. #1
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8

    Ranking within a query for multiple fields


    I hope I am stating this correctly. I can get a query to rank on one variable. What I am trying to do is, take a list of dozens of golfers. Each golfer has multiple golf scores, from one to thirty five. I am trying to rank each golfer's scores within a query, without having to change the query to each golfer's name. Also, when I try to rank them all at once, it will just rank the scores, regardless of golfer. Or, if I try to group in a report, I get an error. Can one of the professionals here offer any expertise? Eternally grateful, Tim

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    It would help if you show your method, but basically you have to add golfer to your criteria.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8
    Quote Originally Posted by pbaldy View Post
    It would help if you show your method, but basically you have to add golfer to your criteria.
    Thanks, I am new to the forum.

    i have

    SELECT t2.Name,(select count(t1.score)
    From one as T1
    Where T1.score >=T2.score) as rank, t2.score
    from one as t2
    where (((t2.name)="ark in,bill"))
    order by t2.score desc;
    this lets me do one golfer at a time, but this will take forever. Any thoughts?

    tim

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Like I said, try adding the golfer:

    Where T1.score >=T2.score And t1.Name = t2.Name

    Played some golf in your area during a visit last year. Had fun!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8
    Very cool about the golf! This is for a local men's club. I will give it a try. I am mostly a basic user, some of the SQL stuff gives me pause.

    I will ill let you know how I do!

    tim

  6. #6
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8
    Nope, something isn't working. It still ranks the scores, but mixes all of the golfers in together.

  7. #7
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8
    Could it be that I need to order by name, and then by score?

  8. #8
    IrogSinta is offline Competent Performer
    Windows 8 Access 2013
    Join Date
    Jun 2015
    Posts
    103
    Can you give a sampling of data from your table and what the expected result would be?

    Ron

  9. #9
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    What was your complete SQL?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  10. #10
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8
    Hi, sorry for the delay, if still available:
    select t2.name,(select count(t1.score)
    from One as t1
    where t1.score<=t2.score and t1.name=t2.name) as rank,t2.score
    from One as t2
    order by t2.name

    i get a ranking of scores, but I need to group by each golfer. When I try to Group, the numbers in the Rank all turn to zero.

    thanks all!

    tim

  11. #11
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    Can you post the db here, or a representative sample?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8
    Give me a few minutes and I will get a table posted. Thank you

  13. #13
    Timc24 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2015
    Location
    Denver, CO
    Posts
    8

    Ok, sample

    Ok, what I have here is my small database.

    For info, I used something called Differential rather than Score (it is a golf calculation), but Differential is the number to be ranked, and then parsed out by golfer. Only by taking my ranked query and re-posting it into a spreadsheet, and then re-importing it into access as a table was I able to get it to group by golfer name.


    So, by Table "One", query and report


    And, by Table "Rank", query and report. Rank is where I had to do the re-import dance. Sorry, due to size, it made me delete the Rank table, query and report, but I figure you get the idea. If needed I will see if I can re-post.


    I hope this helps, and thanks again in advance!

    Tim
    Attached Files Attached Files

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,643
    The query appears to be correctly ranking within each name. Is the problem when you try to group on name in the report? If so:

    http://allenbrowne.com/subquery-02.h...tiLevelGroupBy

    The first 2 options aren't really practical, and the 3rd didn't work in a test with your db. The 4th should work, as will the 5th. For the 5th, you could automate a process that emptied a temp table, repopulated it with your query data, then opened the report. You could also do the ranking on the report rather than in the query, using DCount().

    I'm familiar with the differential, slope and course rating (as long as there's no quiz!). I looked it up, we played Castle Pines, Fossil Trace and Riverdale during our trip. Enjoyed them all, though Fossil Trace was probably the "coolest" surroundings-wise.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Ranking Data in SQL query
    By snowb1sp19 in forum Access
    Replies: 2
    Last Post: 02-01-2013, 02:19 PM
  2. query to summarize top ranking data
    By CMR in forum Queries
    Replies: 1
    Last Post: 09-17-2012, 02:08 PM
  3. Replies: 12
    Last Post: 05-07-2012, 12:41 PM
  4. Ranking (Look for previous ranking)
    By leobear in forum Queries
    Replies: 3
    Last Post: 01-10-2012, 05:58 PM
  5. ranking: can i query a report?
    By stevepcne in forum Reports
    Replies: 2
    Last Post: 11-20-2011, 01:03 AM

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