Q&A for amateur radio enthusiasts
-- 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