SELECT TOP 1 p.Id, p.Title, SUM(CASE WHEN v.VoteTypeId = ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Skeptics

Q&A for scientific skepticism

SELECT TOP 1
    p.Id,
    p.Title,
    SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 WHEN v.VoteTypeId = 3 THEN -1 ELSE 0 END) AS TotalVotes
FROM
    Posts p
    INNER JOIN Votes v ON p.Id = v.PostId
WHERE
    p.PostTypeId = 1 -- 1 represents questions
GROUP BY
    p.Id, p.Title
ORDER BY
    TotalVotes DESC;

Enter Parameters

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