upvotes I have for each tag is not consistent with what my page says

0

Please login or register to vote for this query.

(click on this box to dismiss)

https://meta.stackexchange.com/questions/209311

Chess

Q&A for serious players and enthusiasts of chess

-- How many upvotes do I have for each tag?
-- how long before I get tag badges?

DECLARE @UserId int = ##UserId##
DECLARE @UpvoteTypeId int = 2
DECLARE @DownvoteTypeId int = 3


SELECT --TOP 20 
    TagName,
    COUNT(DISTINCT Posts.Id) AS [Answers],
    COUNT(DISTINCT CASE WHEN Posts.CommunityOwnedDate IS NULL 
              THEN Posts.Id
              ELSE NULL
         END) [Non-CW answers],
    SUM(CASE WHEN votetypeid = @UpvoteTypeId 
             THEN 1 
             ELSE 0 
        END) [Upvotes],
    SUM(CASE WHEN Votes.Votetypeid = @UpvoteTypeId
              AND Posts.CommunityOwnedDate IS NULL 
             THEN 1 
             ELSE 0
        END) [Upvotes non CW],
    SUM(CASE WHEN Votes.Votetypeid = @DownvoteTypeId
             THEN 1 
             ELSE 0 
         END) [Downvotes],
    SUM(CASE WHEN Votes.Votetypeid = @DownvoteTypeId  
              AND Posts.CommunityOwnedDate IS NULL 
             THEN 1 
             ELSE 0 
        END) [Downvotes non CW],
    SUM(CASE WHEN Votes.Votetypeid = @UpvoteTypeId  
              AND Posts.CommunityOwnedDate IS NULL 
             THEN 1 
             ELSE 0 
        END) -
    SUM(CASE WHEN votetypeid = @DownvoteTypeId 
              AND Posts.CommunityOwnedDate IS NULL 
             THEN 1 
             ELSE 0 
        END) [Tag Score]
    
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 IN (@UpvoteTypeId, @DownvoteTypeId)
WHERE 
    Posts.OwnerUserId = @UserId
GROUP BY TagName 
ORDER BY [Tag Score] DESC

Enter Parameters

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