SELECT PostId, Accepted, Up - Down AS Score, Up, Down, II...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT
  PostId,
  Accepted,
  Up - Down AS Score,
  Up,
  Down,
  IIF(Up+Down=0, 0.0, 100.0*Up/(Up+Down)) AS UpPct,
  IIF(Up+Down=0, 0.0, 100.0*Down/(Up+Down)) AS DownPct
FROM (
  SELECT 
    PostId,
    SUM(IIF(VoteTypeId=2, 1, 0)) AS Up,
    SUM(IIF(VoteTypeId=3, 1, 0)) AS Down,
    SUM(IIF(VoteTypeId=1, 1, 0)) AS Accepted
  FROM 
    Votes
  GROUP BY
    PostId
  ) s
WHERE
  Accepted > 0
ORDER BY
  DownPct DESC

Enter Parameters

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