Ranking Records

D

David

I ant to assign a ranking to records based on two criteria. Each record
within my DB has a Year and a Quality Scoring. I want to add a field with the
relative rank (counting from 1 upwards) for each recod based on relative
Qualtiy Scoring within the Year.

Can anyone help me with this?
 
M

Marshall Barton

David said:
I ant to assign a ranking to records based on two criteria. Each record
within my DB has a Year and a Quality Scoring. I want to add a field with the
relative rank (counting from 1 upwards) for each recod based on relative
Qualtiy Scoring within the Year.


SELECT *,
(SELECT Count(*)
FROM table As X
WHERE X.Year = table.Year
And X.Score <= table.Score) As Rank
FROM table
 
D

David

Marshall, thanks for the rapid response. I've tried this, and it works well.
One issue though, where I have multiple records with the same Quality Score
they all recieve the same ranking (OK), but the ranking is the higher number
rather than the lower number (not OK). Eg

Customer Year Score Ranking Desired Ranking
A 1999 10 1 1
B 1999 8 4 2
C 1999 8 4 2
D 1999 8 4 2
E 1999 5 5 5

Can you help me fix this?
 
M

Marshall Barton

Sorry, I should have guessed that that's what you wanted.

SELECT *,
(SELECT Count(*)
FROM table As X
WHERE X.Year = table.Year
And X.Score < table.Score) + 1 As Rank
FROM table
 
D

David

Thanks Marshall, that works fine.

Marshall Barton said:
Sorry, I should have guessed that that's what you wanted.

SELECT *,
(SELECT Count(*)
FROM table As X
WHERE X.Year = table.Year
And X.Score < table.Score) + 1 As Rank
FROM table
--
Marsh
MVP [MS Access]

Marshall, thanks for the rapid response. I've tried this, and it works well.
One issue though, where I have multiple records with the same Quality Score
they all recieve the same ranking (OK), but the ranking is the higher number
rather than the lower number (not OK). Eg

Customer Year Score Ranking Desired Ranking
A 1999 10 1 1
B 1999 8 4 2
C 1999 8 4 2
D 1999 8 4 2
E 1999 5 5 5
 
R

rahmad

David said:
Marshall, thanks for the rapid response. I've tried this, and it works well.
One issue though, where I have multiple records with the same Quality Score
they all recieve the same ranking (OK), but the ranking is the higher number
rather than the lower number (not OK). Eg

Customer Year Score Ranking Desired Ranking
A 1999 10 1 1
B 1999 8 4 2
C 1999 8 4 2
D 1999 8 4 2
E 1999 5 5 5

I'm sorry Mr.Marshall
Would you like to help.

Last time I'm trying this

SELECT Test.Customer, Test.Year, Test.Score, (SELECT Count(Test.Score) FROM
Test As X WHERE X.Year = Test.Year And X.Score <= Test.Score) AS Rank
FROM Test
GROUP BY Test.Customer, Test.Year, Test.Score
ORDER BY Test.Score DESC;

and return me

Customer Year Score Ranking Desired Ranking
A 1999 8 5 1
B 1999 6 4 2
C 1999 5 3 3
D 1999 5 3 3
E 1999 4 1 4

I want the biggest score number at the top rank.
Which word should be revised?
Can I sort the rank Ascending?
And how to return top 10 values of the score which is sorted
descendly.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top