Sometimes one needs to rank data based on some field e.g. Students’ Marks, Product Sales etc. In different platforms there are different ways to do it.
In SQL Server and Excel there is RANK function that does the job but in MS Access there is no such built-in function.
However same result can be achieved using a correlated query.
e.g. Consider a dataset of student marks below.
Suppose one wants to rank students based on their marks (rank = 1 for highest marks). Following query can be used to rank them.Code:Students Marks Tony 34 Bob 32 Thor 48 Jack 42 Tom 41 Kate 45 Sid 26
PHP Code:SELECT Students,
(SELECT COUNT(T1.Marks)
FROM
[Table] AS T1
WHERE T1.Marks >= T2.Marks) AS Rank
FROM
[Table] AS T2
ORDER BY Marks DESC



Reply With Quote

Bookmarks