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

--SET SHOWPLAN_TEXT ON
--GO

WITH VotedPosts AS (
  SELECT
    COUNT(*) as [Num Posts],
    CASE p.PostTypeId WHEN 1 THEN 'Question' ELSE 'Answer' END as [Post Type],
    CASE v.VoteTypeId WHEN 2 THEN 'Up' ELSE 'Down' END as [Vote Type]
  FROM
    Posts p
    JOIN Votes v ON v.PostId = p.Id
  WHERE
    (p.PostTypeId = 1 OR p.PostTypeId = 2) -- question or answer
    AND v.VoteTypeId IN (2, 3) -- upvote or downvote
    AND p.Id > 70000000
  GROUP BY
    p.PostTypeId,
    v.VoteTypeId
)

SELECT *
FROM VotedPosts
ORDER BY
  [Post Type] DESC,
  [Vote Type] DESC

Enter Parameters

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