Q&A for professional and enthusiast programmers
sum(case when b.class=1 then 1 else 0 end) as Gold,
sum(case when b.class=2 and u.reputation>5000 then 1 else 0 end) as "Silver + 5k",
sum(case when b.class=3 and u.reputation>10000 then 1 else 0 end) as "Bronze + 10k",
1 as "Jon Skeet"
from (select UserId, Name, min(class) class from Badges where tagbased='true' group by UserId, Name) b
left join Users u on u.Id=b.UserId
group by b.name
order by Gold,"Silver + 5k","Bronze + 10k"