WITH TEMP_VOTES AS ( SELECT PostID, SUM(CASE WHEN VoteTyp...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Motor Vehicle Maintenance and Repair Meta

Q&A about the site for mechanics and DIY enthusiast owners of cars, trucks, and motorcycles

WITH TEMP_VOTES 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 TEMP_VOTES 
  ORDER BY Upvotes DESC 

UNION

  SELECT TOP 10 PostID, Downvotes AS Votes
  FROM TEMP_VOTES 
  ORDER BY Downvotes DESC 
) S
ORDER BY VOTES
;

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results