Most gold, silver, bronze badges

1

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

SELECT TOP(##num?200##)
  RANK() OVER(
            ORDER BY 
            sum(case when class = 1 then 1 else 0 end) DESC,
            sum(case when class = 2 then 1 else 0 end) DESC,
            sum(case when class = 3 then 1 else 0 end) DESC,
            count(Id) DESC
          ),
  UserId AS [User Link],
  sum(case when class = 1 then 1 else 0 end) AS gold,
  sum(case when class = 2 then 1 else 0 end) AS silver,
  sum(case when class = 3 then 1 else 0 end) AS bronze,
  count(Id) AS total
FROM Badges
GROUP BY UserId
ORDER BY gold DESC, silver DESC, bronze DESC, total DESC

Enter Parameters

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