Occupy Stack Overflow!
Q&A for students, teachers, and linguists wanting to discuss the finer points of the French language
-- How Rich Are the 1% (Active Users)
-- Occupy Stack Overflow!
;WITH percentile AS (
SELECT NTILE(100) OVER (ORDER BY Reputation DESC) as p, Reputation, DisplayName
WHERE Reputation >= 200 and datediff(d,lastaccessdate,getdate()) <= 60
total AS (
SELECT SUM(Reputation) as total FROM percentile
SELECT count(*) as [Active in the last 60 days], 'The ' + CASE p WHEN 1 THEN '1' ELSE '99' END + '%' AS Who, SUM(Reputation) AS Rep, CAST(SUM(Reputation) AS DECIMAL(19,2)) / total.total * 100 AS PctShareOfWealth
FROM percentile, total
GROUP BY CASE p WHEN 1 THEN '1' ELSE '99' END, total.total