Most gold, silver, bronze tag 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

;  with badges_cte as
(SELECT TOP(##num?200##)
  b.UserId AS uid,
  sum(case when b.class = 1 then 1 else 0 end) AS gold,
  sum(case when b.class = 2 then 1 else 0 end) AS silver,
  sum(case when b.class = 3 then 1 else 0 end) AS bronze,
  count(b.Id) AS total
FROM Badges b INNER JOIN tags t ON t.tagname=b.name
GROUP BY b.UserId
)

SELECT
  RANK() OVER(ORDER BY gold DESC, silver DESC, bronze DESC, total DESC),
  uid AS [User Link], gold, silver, bronze, total
FROM badges_cte  
ORDER BY gold DESC, silver DESC, bronze DESC, total DESC

Enter Parameters

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