Rank and Percentile including total Users and Percentile as %

1

Please login or register to vote for this query.

(click on this box to dismiss)

Craft CMS Meta

Q&A about the site for administrators, end users, developers and designers for Craft CMS

-- StackOverflow Rank and Percentile

-- Based off of Cade Roux's Rank and Percentile Query

WITH Rankings AS (
SELECT Id, Ranking = ROW_NUMBER() OVER(ORDER BY Reputation DESC)
FROM Users
)
,Counts AS (
SELECT Count = COUNT(*)
FROM Users
WHERE Reputation > ##ReputationMinimum##
)
SELECT Id, (SELECT Reputation FROM Users WHERE Id = ##UserId##) AS Reputation, Ranking, (SELECT Count FROM Counts) AS[Total Users], LEFT(CAST((CAST(Ranking AS decimal(10, 5)) / (SELECT Count FROM Counts))*100 AS VARCHAR),5) + '%' AS Percentile
FROM Rankings
WHERE Id = ##UserId##

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results