Q&A for people studying math at any level and professionals in related fields
set nocount on declare @VoteStats table ([year] int,up int, down int) insert @VoteStats select [year] = datepart(yy,Votes.CreationDate), up = sum(case when VoteTypeId = 2 then 1 else 0 end), down = sum(case when VoteTypeId = 3 then 1 else 0 end) from Votes inner join Posts ON (Posts.id = Votes.PostId) where VoteTypeId in (2,3) and PostTypeId = 1 group by datepart(yy,Votes.CreationDate) set nocount off select [year],(100 * down/up) as percentage, up, down from @VoteStats order by [year] desc