Shows the questions that come closest to having the same number of up- and downvotes, but still have a positive total. The difference is expressed as a percentile ratio of total upvotes, i.e., the difference between the number of up- and downvotes as a percentage of the total number of upvotes.
For example, a post with 10 upvotes and 9 downvotes has a difference of 1 vote = 10% of of 10 upvotes = 10% ratio.
Q&A for science fiction and fantasy enthusiasts
Set STATISTICS IO ON;
set nocount on
declare @VoteStats table (PostId int, up int, down int)
up = sum(case when VoteTypeId = 2 then 1 else 0 end),
down = sum(case when VoteTypeId = 3 then 1 else 0 end)
where VoteTypeId in (2,3)
group by PostId
set nocount off
select top 100 p.id as [Post Link], up, down, (cast((up - down) as decimal) / up * 100) as ratio from @VoteStats
join Posts p on PostId = p.Id
where up < down and up > 7 and p.CommunityOwnedDate is null
order by ratio desc, down desc, up desc