A dense_rank() is logically the same as ranking without duplicated values
and then, join the initial data with the previous result you got.
The word partition, in this case, is the syntax used by MS SQL Server to
signify that the rank has to be performed 'by group' (as example, in each
country, rank the cities by their population, to the largest city, in each
country, will get a rank of 1.
So, assume q1 supply the values without dup:
SELECT f1, f2
FROM somewhere
GROUP BY f1, f2
as example, then, you can rank group by f1 with your favorite method, I
prefer using joins:
SELECT a.f1, a.f2, COUNT(*) AS dense_rank
FROM q1 AS a INNER JOIN q1 AS b
ON a.f1=b.f1
AND a.f2 >= b.f2
GROUP BY a.f1, a.f2
(note that here, rank = 1 to the lowest value, not the highest. To reverse
the ordering, change >= to <= in the ON clause)
saved as qrank, then
SELECT *, qrank.dense_rank
FROM somewhere INNER JOIN qrank
ON somewhere.f1=qrank.f1
AND somewhere.f2=qrank.f2
return your initial data WITH the dense_rank value, by group. You can add an
ORDER BY clause, for visual inspection about the validity of the result:
ORDER BY somewhere.f1, somewhere.f2
Vanderghast, Access MVP