Q&A about the site for researchers and developers who explore the principles of a system through analysis of its structure, function, and operation
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 = ##POSTID## GROUP BY Posts.id ) VotesCount GROUP BY UpVotes, DownVotes ORDER BY UpVotes DESC