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)

Blender Meta

Q&A about the site for people who use Blender to create 3D graphics, animations, or games

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