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

1

Please login or register to vote for this query.

(click on this box to dismiss)

Linguistics Meta

Q&A about the site for professional linguists and others with an interest in linguistic research and theory

SELECT
  RANK() OVER (ORDER BY Id) AS No,
  SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END)
    OVER (ORDER BY Id ROWS UNBOUNDED PRECEDING) AS Ups,
  SUM(CASE WHEN VoteTypeId = 3 THEN -1 ELSE 0 END)
    OVER (ORDER BY Id ROWS UNBOUNDED PRECEDING) AS Downs,
  SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE -1 END)
    OVER (ORDER BY Id ROWS UNBOUNDED PRECEDING) AS Score
FROM Votes
WHERE
  PostId = ##PostId:int##
  AND
  VoteTypeId BETWEEN 2 AND 3

UNION ALL

SELECT 0 AS No, 0 AS Ups, 0 AS Downs, 0 AS Score

ORDER BY No;

Enter Parameters

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