Q&A for professional and enthusiast programmers
select * from ( SELECT Id a -- aggregate , postid -- group by , VoteTypeId -- columns FROM Votes ) src PIVOT ( count(a) -- what we aggregate on FOR VoteTypeId in ([1], [2], [3]) -- accept, upmod, downmod ) pvt order by [2] desc