Q&A for those who create, solve, and study puzzles
-- Most upvoted tags SET ARITHABORT OFF SET ANSI_WARNINGS OFF SELECT TagName, Count, SUM(CASE WHEN VoteTypeID = 2 THEN 1 ELSE 0 END) As UpVotes, SUM(CASE WHEN VoteTypeID = 3 THEN 1 ELSE 0 END) As DownVotes, SUM(CASE WHEN VoteTypeID = 2 THEN 1 ELSE 0 END)/ SUM(CASE WHEN VoteTypeID = 3 THEN 1 ELSE 0 END) AS Ratio FROM Tags INNER JOIN PostTags ON PostTags.TagId = Tags.id INNER JOIN Posts ON Posts.ParentId = PostTags.PostId INNER JOIN Votes ON Votes.PostId = Posts.Id and VoteTypeId IN (2, 3) GROUP BY TagName, Count ORDER BY Ratio DESC