DECLARE @Privileges TABLE (Name VARCHAR(20), Rep INT) IN...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

--- This is an adapted version of https://data.stackexchange.com/stackoverflow/query/361594/users-by-privilege

DECLARE @Privileges TABLE (Name VARCHAR(20), Rep INT)
INSERT INTO @Privileges VALUES ('Basic mod access', 15)
INSERT INTO @Privileges VALUES ('Meta access', 5)
INSERT INTO @Privileges VALUES ('Total', 0);

SELECT
  tmp.Name AS Privilege,
  pr.Rep,
  tmp.Count
FROM
  @Privileges pr INNER JOIN (
    SELECT 
       COUNT(*) AS Count, p.Name
    FROM @Privileges p, Users u
    WHERE u.Reputation >= p.Rep
    GROUP BY p.Name
  ) tmp ON pr.Name = tmp.Name
ORDER BY
  pr.Rep DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results