Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles
WITH VoteCounts AS ( SELECT PostId, SUM(CASE WHEN VoteTypeId = 2 THEN 1 ELSE 0 END) AS Upvotes, SUM(CASE WHEN VoteTypeId = 3 THEN 1 ELSE 0 END) AS Downvotes FROM Votes GROUP BY PostId ) SELECT PostId ,VOTES FROM ( SELECT TOP 10 PostId ,Upvotes AS VOTES FROM VoteCounts ORDER BY Upvotes DESC UNION SELECT TOP 10 PostId, Downvotes AS VOTES FROM VoteCounts ORDER BY Downvotes DESC ) AS Combined ORDER BY PostId;