Top Answerers for Tag: score = number of answers with score >= x

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

-- Top 20 users for a given tag, ordered by descending score with
--   score = number of questions for ##TagName##
--             with a score >= ##LowerBound##

-- TagName: Which tag to list Top Answerers for
-- LowerBound: Minimum score for answers to be included (int)

DECLARE @LowerBound int = ##LowerBound:int##

SELECT TOP 20
    P.OwnerUserId as [User Link],
    SUM(
      CASE WHEN P.Score < @LowerBound THEN 0 ELSE 1 END      
    ) AS 'TotalScore',
    COUNT(*) AS '#Answers'
FROM Posts P
    INNER JOIN PostTags PT on PT.PostId = P.ParentId
    INNER JOIN Tags T on T.Id = PT.TagId
WHERE
    T.TagName = '##TagName##' AND
    P.OwnerUserId IS NOT null
    
GROUP BY P.OwnerUserId
ORDER BY 'TotalScore' DESC

Enter Parameters

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