Top 2000 Users, ranked by number of Badges, with badge type/class

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT  TOP 2000  -- Keep from crashing on big data, like for Stack Overflow
            UserId                                              AS [User Link]
            , COUNT (Id)                                        AS [Total]
            , 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
            , SUM (CASE WHEN TagBased=1 AND Class = 1  THEN 1  ELSE 0  END) AS [Tag Gold]
            , SUM (CASE WHEN TagBased=1 AND Class = 2  THEN 1  ELSE 0  END) AS [Tag Silver]
            , SUM (CASE WHEN TagBased=1 AND Class = 3  THEN 1  ELSE 0  END) AS [Tag Bronze]
FROM        Badges
GROUP BY    UserId
ORDER BY    [Total] DESC
            , Gold DESC
            , Silver DESC
            , Bronze DESC

Enter Parameters

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