How many upvotes do I have towards tag-specialist badges?

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

-- Enter Query Title
-- Enter Query Description

DECLARE @UserId int = ##UserId##
;
WITH detail as (
  SELECT TOP 50 
      TagName,
      -- 20/80/200    for bronze/silver/gold badges
      COUNT(distinct Posts.Id) as Posts,
      -- 100/400/1000 for bronze/silver/gold badges
      SUM(case when Votes.VoteTypeId = 2 then 1
               when Votes.VoteTypeId = 3 then -1
          end) AS Score,
      SUM(case when Votes.VoteTypeId = 2 then 1 end) AS Upvotes,
      SUM(case when Votes.VoteTypeId = 3 then 1 end) AS Downvotes,
      SUM(case when Votes.VoteTypeId = 1 then 1 end) AS Accepted
  FROM Tags
      INNER JOIN PostTags ON PostTags.TagId = Tags.id
      INNER JOIN Posts ON Posts.ParentId = PostTags.PostId
      LEFT JOIN Votes ON Votes.PostId = Posts.Id
  WHERE 
      Posts.OwnerUserId = @UserId
      AND Posts.CommunityOwnedDate IS NULL
  GROUP BY TagName 
)
, badge as (
  SELECT *
    , case when Posts > 40 then 1 end as x 
  FROM detail
)
SELECT *
FROM badge
ORDER BY Score DESC

Enter Parameters

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