MinReputation: base percentile calculation on users with a reputation of MinReputation or more. UserId: The user id, e.g. 7017466 Results: Id: UserId Ranking: position in the ranking, the lower the better Percentile: expressed 0-100 TotalUsers: Total users with MinReputation or more
Q&A for administrators, end users, developers and designers for Craft CMS
-- StackOverflow Rank and Percentile WITH Rankings AS ( SELECT Id, Ranking = ROW_NUMBER() OVER(ORDER BY Reputation DESC) FROM Users ) ,Counts AS ( SELECT Count = COUNT(*) FROM Users WHERE Reputation >= ##MinReputation## ) SELECT Id, Ranking , CAST(Ranking AS decimal(20, 5)) * 100 / (SELECT Count FROM Counts) AS Percentile , (SELECT Count FROM Counts) AS TotalUsers FROM Rankings WHERE Id = ##UserId##