I'm trying to find out the position of each given record of a query in 0-100 scale. I use PERCENT_RANK
ranking function this way:
select Term, Frequency, percent_rank() over (order by Frequency desc) * 100
from Words
But when I look at the results, instead of seeing a column that starts from 0 and goes up to 100, I see a column that starts from 0 and goes up to 37.xxxx.
Though BOL does not explicitly mention that the result is distributed over 0-100 scale, my understanding from the word percent
made me use this ranking function.
What do I miss here?
Best Answer
This will happen if you have ties for the lowest frequency
The below shows an example along with a calculated column showing how the
PERCENT_RANK
is calculated.As the highest
RANK
is3
when ordered descending and there are 7 rows. The(rk -1)/(rn -1)
is(3-1)/(7 -1)
=2/6
=33.3%