Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles
select top 20 v.*, p.Id [Post Link] from Posts p inner join ( select PostId, sum(case when VoteTypeId = 2 then 1 else 0 end) up, sum(case when VoteTypeId = 3 then 1 else 0 end) down from Votes group by PostId ) v on p.Id = v.PostId where OwnerUserId = 396458 order by down desc, up desc, id asc -- Enter Query Title