Find amount of downvotes of a post

0

Please login or register to vote for this query.

(click on this box to dismiss)

Woodworking

Q&A for professional and amateur woodworkers

-- How many upvotes do I have 

DECLARE @UserId int = ##UserId##

SELECT UpVotes, DownVotes, COUNT(*) AS AnswersCount
FROM (
  SELECT 
      SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS UpVotes,
      SUM(CASE WHEN VoteTypeId = 3 THEN -1 ELSE 0 END) AS DownVotes
      From Posts
      INNER JOIN Votes ON Votes.PostId = Posts.Id and (VoteTypeId = 2 OR VoteTypeId = 3)
  WHERE 
      Posts.Id = @UserId
  GROUP BY Posts.id 
) VotesCount
GROUP BY UpVotes, DownVotes 
ORDER BY UpVotes DESC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results