To create a more linear distribution, I added a calculated column to the data table, HITS_SQRT HITS_SQRT AS (CONVERT([int],sqrt(HITS*4),(0))) PERSISTED .
Using this column, you can calculate the target number of hits per percentile.
select @hitsPerGroup=SUM(HITS_SQRT)/(@numGroups -1) -@numGroups , @dataPoints=COUNT(*) FROM
Then the script creates a temporary table with ROW_NUMBER () sorted by the number of hits, and repeats the rows in descending order, updating its percentile from 100 to 1. The total amount of hits is @hitsPerGroup and when @hitsPerGroup is @hitsPerGroup , the percentile goes down from 100 to 99, from 99 up to 98 etc.
Then the source data table is updated with its percentile. To speed up the update, there is a temp worksheet index.
Full script using #Rank_Table as the source data table.
--Create Test Data CREATE TABLE
Performance is not stellar, but it achieves the goal of a smooth glide distribution.
Laramie
source share