Answered by:
How to Get Rank in Access Query?

Question
-
Hello all,
I want to Get Rank according to Total but Rank should not be skipped.
For Example if two person Get 1 rank then 3rd should be started with 2 not 3.
please Help me with this Query.
I am using Microsoft Access as my back-end tool.
My Query is like this
SELECT
(SELECT COUNT(T1.*) + 1
FROM
[tbl1] AS T1
WHERE T1.Total > T2.Total ) AS Rank
FROM
[tbl2] AS T2
order by T2.Total
Thank u...
- Edited by Vimal Chotaliya Thursday, April 14, 2016 10:19 AM
- Moved by CoolDadTx Thursday, April 14, 2016 2:08 PM Office related
Thursday, April 14, 2016 10:16 AM
Answers
-
This is called dense rank:
You need to calculate the rank for the measure and join the additional rows. E.g.
SELECT O.* , ( SELECT COUNT(*) FROM ( SELECT T.Total FROM Table1 T GROUP BY T.Total ) I WHERE I.Total >= O.Total ) DenseRank FROM Table1 AS O ORDER BY O.Total;
- Proposed as answer by Edward8520Microsoft contingent staff Friday, April 15, 2016 2:09 AM
- Marked as answer by Vimal Chotaliya Friday, April 15, 2016 8:25 AM
- Edited by Stefan Hoffmann Sunday, April 17, 2016 11:10 AM wrong comparison operator
Thursday, April 14, 2016 12:24 PM
All replies
-
This is called dense rank:
You need to calculate the rank for the measure and join the additional rows. E.g.
SELECT O.* , ( SELECT COUNT(*) FROM ( SELECT T.Total FROM Table1 T GROUP BY T.Total ) I WHERE I.Total >= O.Total ) DenseRank FROM Table1 AS O ORDER BY O.Total;
- Proposed as answer by Edward8520Microsoft contingent staff Friday, April 15, 2016 2:09 AM
- Marked as answer by Vimal Chotaliya Friday, April 15, 2016 8:25 AM
- Edited by Stefan Hoffmann Sunday, April 17, 2016 11:10 AM wrong comparison operator
Thursday, April 14, 2016 12:24 PM -
Thank u...:)Friday, April 15, 2016 8:25 AM
-
Sunday, April 17, 2016 3:37 AM
-
Yes.
The most inner SELECT with the GROUP BY returns the unique values. This assures that we get the dense rank. Without GROUP BY we get the normal rank.
Then we evalutate the rank by counting the rows. Caveat: There was a typo in m original answer, I used an = instead of >=.
Sunday, April 17, 2016 11:08 AM