dbasetrouble
asked on
Ranking in Access
I have an access table that has points calulated.
vendor 1
Rating 1 60 pts
Rating 2 40 pts
Rating 3 40 pts
Rating 4 30 pts
Rating 5 20 pts
I have created a query that ranks the ratings. It comes out so:
1
2
2
4
5
What I need it to do is a distinct rating like so:
1
2
2
3
4
vendor 1
Rating 1 60 pts
Rating 2 40 pts
Rating 3 40 pts
Rating 4 30 pts
Rating 5 20 pts
I have created a query that ranks the ratings. It comes out so:
1
2
2
4
5
What I need it to do is a distinct rating like so:
1
2
2
3
4
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I see your problem, I don't have an answer for that off the top of my head. Sorry!
1 one solution is to order it by rating, then take the row number
2 another is to use WITH TIES
source: http://harriyott.com/2007/06/with-ties-sql-server-tip.aspx
Which gives:
Name Score
Brenda 42
Maureen 41
Edwin 41
Terry 40
Rupert 39
Arthur 39
Paula 39
If you choose to use the second method. You can query into it from another query and select the rankings that way
2 another is to use WITH TIES
source: http://harriyott.com/2007/06/with-ties-sql-server-tip.aspx
SELECT TOP 5 WITH TIES Name, Score
FROM Scores
ORDER BY Score DESC
Which gives:
Name Score
Brenda 42
Maureen 41
Edwin 41
Terry 40
Rupert 39
Arthur 39
Paula 39
If you choose to use the second method. You can query into it from another query and select the rankings that way
Actually this will probably work better
SELECT * FROM
(SELECT id, points from member1 )Y INNER JOIN
(SELECT DISTINCT points, count(*)as rating FROM member1 GROUP BY points ORDER BY points )X ON Y.points = X.points
ORDER BY Points
SELECT * FROM
(SELECT id, points from member1 )Y INNER JOIN
(SELECT DISTINCT points, count(*)as rating FROM member1 GROUP BY points ORDER BY points )X ON Y.points = X.points
ORDER BY Points
ASKER
Thanks for the help. Figured out a much easier way. I created a query call distinctrank. I added just the points field and change the query properties to uniquevalue=Yes. I then create a expression field in the regular query that looks like this:
Rank1: DCount("*","distinctrank", "Points >" & [Points])+1
Work out great.
Rank1: DCount("*","distinctrank",
Work out great.
great to hear, if you have a large table the last one i added might work quicker, but it looks like you might not need it
Select Distinct Ranking