Cumulative, time-scaled up/down history of a single post

1

Please login or register to vote for this query.

(click on this box to dismiss)

Aviation

Q&A for aircraft pilots, mechanics, and enthusiasts

WITH Raw AS (
  SELECT
    CreationDate,
    SUM(CASE WHEN VoteTypeId = 2 THEN 1 END) AS Ups,
    SUM(CASE WHEN VoteTypeId = 3 THEN 1 END) AS Downs
  FROM Votes
  WHERE
    PostId = ##PostId:int##
    AND
    VoteTypeId BETWEEN 2 AND 3
  GROUP BY CreationDate
)
SELECT
  CreationDate,
  SUM(Raw.Ups)
    OVER (ORDER BY CreationDate ROWS UNBOUNDED PRECEDING) AS Ups,
  -SUM(Raw.Downs)
    OVER (ORDER BY CreationDate ROWS UNBOUNDED PRECEDING) AS Downs,
  SUM(Raw.Ups-Raw.Downs)
    OVER (ORDER BY CreationDate ROWS UNBOUNDED PRECEDING) AS Score
FROM Raw
ORDER BY CreationDate;

Enter Parameters

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