Table of population as a function of number of votes on the post


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 A.Count as 'Votes', COUNT(*) as 'Count', ROUND(COUNT(*) / (CAST(B.Total AS float)) * 100, 5) as '%age'


  COUNT(*) AS 'Count'
  FROM Posts
    JOIN Votes
    ON Votes.PostId = Posts.Id
  WHERE Votes.VoteTypeId = 2 or Votes.VoteTypeId = 3
  GROUP BY Posts.Id) as A


  COUNT(*) as 'Total'
  FROM Posts
  WHERE Posts.PostTypeId = 1 or Posts.PostTypeId = 2 or Posts.PostTypeId = 3) as B

ON 1 = 1

GROUP BY A.Count, B.Total
ORDER BY '%age' DESC, 'Votes' DESC;

Enter Parameters

Switch to meta site
loading Hold tight while we fetch your results