Tag badges

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

DECLARE @UserId int = ##UserId##

SELECT * FROM (
SELECT --TOP 20 
    TagName Tag,
    COUNT(votes.id) UpVotes,
    COUNT(DISTINCT posts.id) Answers
FROM Tags
    INNER JOIN PostTags ON PostTags.TagId = Tags.id
    INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
    INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId = 2
WHERE 
    Posts.OwnerUserId = @UserId
    and Posts.CommunityOwnedDate IS NULL
GROUP BY TagName 
UNION ALL SELECT '[Bronze badge]' Tag, 100 UpVotes, 20 Answers
UNION ALL SELECT '[Silver badge]' Tag, 400 UpVotes, 80 Answers
UNION ALL SELECT '[Gold badge]' Tag, 1000 UpVotes, 200 Answers
) foo
ORDER BY
  CASE WHEN UpVotes > 5*Answers then 5*Answers ELSE UpVotes END
DESC

Enter Parameters

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