Up votes and down votes, questions and answers

1

Please login or register to vote for this query.

(click on this box to dismiss)

Lifehacks

Q&A for people looking to bypass life's everyday problems with simple tricks

SELECT
  -- the kruft here is just for pretty output formatting
  IIF(p.PostTypeId = 1, 'Questions', 'Answers') AS [Post Type],
  IIF(v.VoteTypeId = 2, 'Up Votes', 'Down Votes') AS [Vote Type],
  COUNT(*) AS [Count]
FROM
  Posts p INNER JOIN Votes v ON p.Id = v.PostId
WHERE
  -- open questions only (roughly):
  p.ClosedDate IS NULL 
  -- questions (1) and answers (2) only:
  AND (p.PostTypeId = 1 OR p.PostTypeId = 2) 
  -- upvotes (2) and downvotes (3) only
  AND (v.VoteTypeId = 2 OR v.VoteTypeId = 3) 
GROUP BY
  -- group into questions + answers and upvotes + downvotes for counting
  p.PostTypeId, v.VoteTypeId

Enter Parameters

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