SELECT TOP 10 p.Id AS [Post Link], CASE WHEN p.PostTypeId...

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

SELECT TOP 10
    p.Id AS [Post Link],
    CASE 
        WHEN p.PostTypeId = 1 THEN 'Question'
        WHEN p.PostTypeId = 2 THEN 'Answer'
        ELSE 'Unknown'
    END AS [Post Type],
    SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 ELSE 0 END) AS Upvotes,
    SUM(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE 0 END) AS Downvotes,
    SUM(CASE WHEN v.VoteTypeId IN (2, 3) THEN 1 ELSE 0 END) AS TotalVotes
FROM
    Posts p
    INNER JOIN Votes v ON p.Id = v.PostId
GROUP BY
    p.Id,
    p.PostTypeId
ORDER BY
    TotalVotes DESC;

Enter Parameters

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