Number of posts with upvotes vs. downvotes

0

Please login or register to vote for this query.

(click on this box to dismiss)

Bicycles

Q&A for people who build and repair bicycles, people who train cycling, or commute on bicycles

WITH PostData AS (SELECT
  v.PostId,
  case p.PostTypeId when 1 then 1 else null end as IsQuestion,
  case p.PostTypeId when 2 then 1 else null end as IsAnswer,
  MAX(case v.VoteTypeId when 2 then 1 else null end) as Upvoted,
  MAX(case v.VoteTypeId when 3 then 1 else null end) as Downvoted
FROM Votes v
INNER JOIN Posts p ON
  v.PostId = p.Id
GROUP BY v.PostId, v.VoteTypeId, p.PostTypeId)

SELECT
  COUNT(Upvoted) as [Upvoted posts],
  COUNT(Downvoted) as [Downvoted posts]--,
--  SUM(IsQuestion * Upvoted) as [Upvoted Qstns],
--  SUM(IsQuestion * Downvoted) as [Downvoted Qstns],
--  SUM(IsAnswer * Upvoted) as [Upvoted Answers],
--  SUM(IsAnswer * Downvoted) as [Downvoted Answers]
FROM PostData

Enter Parameters

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