Top Answerers: order by badge, then by score descending

0

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 20
    OwnerUserId AS [User Link],
    TopBadge,
    SUM(Score) AS TotalScore,
    COUNT(*) AS NofAnswers
FROM Posts P
    INNER JOIN PostTags PT ON PT.PostId = P.ParentId
    INNER JOIN Tags T ON T.Id = PT.TagId
    INNER JOIN (
        SELECT
            UserId,
            MIN(Class) AS TopBadge
        FROM Badges B
        WHERE
            Name = '##TagName##' AND
            TagBased > 0
        GROUP BY UserId
    ) BB ON BB.UserId = P.OwnerUserId
WHERE
    T.TagName = '##TagName##' AND
    P.OwnerUserId IS NOT null AND
    P.CommunityOwnedDate IS null AND
    P.PostTypeId = 2
GROUP BY P.OwnerUserId, TopBadge
ORDER BY TopBadge, TotalScore DESC

Enter Parameters

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