Votes Per Tag

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for programmers

SELECT
  ROW_NUMBER() OVER (ORDER BY DownVotesPct DESC) AS Rank,
  *
FROM (
  SELECT
    t.TagName,
    t.Count,
    UpVotes,
    DownVotes,
    (UpVotes + DownVotes) AS TotalVotes,
    1.0 * UpVotes / (UpVotes + DownVotes) AS UpVotesPct,
    1.0 * DownVotes / (UpVotes + DownVotes) AS DownVotesPct
  FROM 
    Tags t INNER JOIN (
      SELECT
        p.TagId,
        SUM(CASE v.VoteTypeId WHEN 2 THEN 1 ELSE 0 END) AS UpVotes,
        SUM(CASE v.VoteTypeId WHEN 3 THEN 1 ELSE 0 END) AS DownVotes
      FROM
        PostTags p INNER JOIN Votes v ON v.PostId = p.PostId
      WHERE
        v.VoteTypeId = 2 OR v.VoteTypeId = 3
      GROUP BY
        p.TagId
      ) tmp
    ON t.Id = tmp.TagId
  WHERE
    (UpVotes + DownVotes) > 10
  ) res
ORDER BY
  DownVotesPct DESC

Enter Parameters

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