473,395 Members | 1,652 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Dealing with Ties in a Rank Query in Access

Hi

I have a query that ranks some scores, which you kind folks helped me with. However the query isn't quite ranking tied scores as I would like. Instead of 1,2,2,4 it provides 1,3,3,4.

I have been looking at various posts and a help page at http://support.microsoft.com/kb/120608 but I can't get my syntax right to perform the query.

I am getting a little desparate as I need the db at a competition tomorrow!

Many many thanks


Here is my query:
Expand|Select|Wrap|Line Numbers
  1. SELECT   Res1.Class_ID, Res1.Dog_Handler_ID, Res1.Club, Res1.Score, COUNT(*) as Rank
  2. FROM     (
  3.          SELECT Class_ID, Dog_Handler_ID, Club, Score
  4.          FROM Q_Results
  5.          GROUP BY Class_ID, Dog_Handler_ID, Club, Score) AS Res1
  6.          INNER JOIN
  7.          (
  8.          SELECT Class_ID, Dog_Handler_ID, Club, Score
  9.          FROM Q_Results
  10.          GROUP BY Class_ID, Dog_Handler_ID, Club, Score
  11.          ) AS b
  12.   ON     Res1.Class_ID = b.Class_ID
  13.  AND     Res1.Score >= b.Score
  14. GROUP BY Res1.Class_ID, Res1.Dog_Handler_ID, Res1.Club, Res1.Score
  15. ORDER BY Res1.Class_ID, Res1.Score, COUNT(*)
Mar 19 '10 #1
3 4206
NeoPa
32,556 Expert Mod 16PB
Ranking is normally done by counting (or summing if you prefer) the number of items in the list which are better, using your own definition of better of course.

In this case I suspect changing >= into = on line #13 would probably sort you out. You will need to add 1 to the value received though. This would return 0, 1, 1, 2 otherwise.
Mar 19 '10 #2
Hmm - that didn't work - it changed everything the ranking altogether and I only got ranks 1 and 2 rather than 1 through 17 that I was getting before.

Thank you though!
Mar 19 '10 #3
NeoPa
32,556 Expert Mod 16PB
How about :
Expand|Select|Wrap|Line Numbers
  1. SELECT   Class_ID,
  2.          Dog_Handler_ID,
  3.          Club,
  4.          Score,
  5.          (SELECT COUNT(*)
  6.           FROM   Q_Results
  7.           WHERE  Score>QR.Score)+1 AS Rank
  8.  
  9. FROM     Q_Results AS QR
  10.  
  11. ORDER BY Class_ID,
  12.          Score
Mar 20 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: bughunter | last post by:
I discover next problem I have view definition with rank() create view vTEST as select c1, c2, c3, ... -- problem area start , rank() over (order by c3) as RNK -- problem area stop from...
3
by: Elden Carnahan | last post by:
I am trying to derive rank values in a query, just as one would with the Rank function in Excel. Can't see how to do this elementary task. Can anyone advise?
5
by: ED | last post by:
I currently have vba code that ranks employees based on their average job time ordered by their region, zone, and job code. I currently have vba code that will cycle through a query and ranks each...
1
by: Helge's | last post by:
I have a table like this: Numbers 10 20 30 40 How can I make a sql in Access? I want it like this:
2
by: orenlevy1 | last post by:
Hi Everyone. I have a problem that I could not figure out what to do with it. I have a couple of tables and views. All have the same unique ID. When a user try to do a search on our web site...
1
by: Bob | last post by:
Hi all, I want to incorporate several types of different rankings to a Make Table Query I have then use the rank for calculations. I want to calculate rankings based on how much each client has...
39
by: OtheymAverian | last post by:
Using Access '02, Windows XP Pro SP2 I have a Report that Contains data that is sorted by name and have been asked to add a field that would output a rank based on a numerical (currency) field. ...
6
by: queezer | last post by:
Hi everyone, I'm bulding a query that returns the sales per week and per branche, e.g.: Week Branch Sales RANKING 1st AAA 10 1 1st BBB 15 2 2nd AAA ...
6
by: sstidham | last post by:
I have a query which calculates the data from two table and then yields the number of points based on various calculations for each category. Essentially we are trying to rank our Agents based on...
3
by: WataMess | last post by:
Hi all, I am a just starting to build my own formula's and limited skills w/ writing sql. I am having some issues trying to rank by an id and based on the rate of a particular procedure, we...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.