Re: Ranking Scores in a Query



Here is a solution with a join:


SELECT a.fee, a.key, LAST(a.score), COUNT(*) AS rank
FROM yourQuery AS a INNER JOIN yourQuery AS b
ON a.fee = b.fee
AND a.key =b.key
AND a.score <= b.score
GROUP BY a.fee, a.key


If there are ex-equo, they all got the higest rank: 10, 20, 20, 30 will be
respectively ranked 1, 3, 3, 4


SELECT a.fee, a.key, LAST(a.score), 1+ COUNT(*) AS rank
FROM yourQuery AS a LEFT JOIN yourQuery AS b
ON a.fee = b.fee
AND a.key =b.key
AND a.score < b.score
GROUP BY a.fee, a.key


will return 1, 2, 2, 4




Hoping it may help,
Vanderghast, Access MVP



"Steve S" <SteveS@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:AF15BBA2-FFE9-401E-98C9-2EB59204F55A@xxxxxxxxxxxxxxxx
I have a query that uses 3 tables and 3 Xtab queries to use as record
source
for a report. Three of the numeric fields created as output from this
query
are:

Fee Key Score
876 10 236.8
876 10 287.0
876 10 123.7
876 13 231.9
876 13 321.5

I need to add a 'Rank' field to produce:

Fee Key Score Rank
876 10 236.8 2
876 10 287.0 1
876 10 123.7 3
876 13 231.9 2
876 13 321.5 1

The final result will be that the highest score, within Key, within Fee is
First and so forth. Is this possible to do with a query. I have other
ranking routines where the values being ranked are in a table but I would
like to do this in a query if possible. I just can't seem to get it to
work.

Help is appreciated



.



Relevant Pages

  • Re: ranking calculated fields in a query
    ... I needed to create 3 queries such as you reffered to as qRank. ... Each 'Rank' query uses the ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: ranking calculated fields in a query
    ... resolving the ties - I can't help any more with this. ... the rank to appear the way you need it. ... I will look at the other query and reply later. ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: ranking calculated fields in a query
    ... I needed to create 3 queries such as you reffered to as qRank. ... Each 'Rank' query uses the associated ... FROM (ModelingXTab INNER JOIN Twirlers ON ModelingXTab.= ...
    (microsoft.public.access.queries)
  • Re: Conversion of Rows into Colums
    ... If you have the data as you shown in the result, then you should be able to construct a pivot query. ... If you are saying you need an SQL statement to generate the rank based on ID and IDNew then the following should work ... Access MVP 2002-2005, 2007-2009 ... In the following I will count the records within the recordset related to the id. ...
    (microsoft.public.access.modulesdaovba)
  • Re: Join query
    ... ranking query (where each distinct name is ... given a distinct "rank") then use the xtab method ... FROM tblGrade As t1; ... GroupNo Grader Points Rank ...
    (microsoft.public.access.queries)