As a technology demonstration I share this query that uses the PIVOT feature of SQL Server. It turns out the Badges table is perfect to use. The resulting query isn't necessarily easier to grasp then the one offered by Martin.
rank() over(order by ++ desc) [rank] -- and ranking functions works
, UserId as [User Link] -- we pivot over this column
,  [Gold] -- first value column
,  [Silver] -- 2nd value column
,  [Bronze] -- 3rd value column
, ++ [total] -- \o/ we can calc as well
-- this is the main resultset
count(id) -- aggregate count can work here
class in (, , ) -- each value in 'class' becomes a column
order by ++ desc
Keep in mind SEDE is updated once a week on Sunday.
Use the fine SEDE Tutorial written by the admirable Monica Cellio.
Say "Hi" in SEDE chat.