Q&A about the site for members of the workforce navigating the professional setting
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