Unanimous Upvotes

1

Please login or register to vote for this query.

(click on this box to dismiss)

Top 100 most highly upvoted posts that haven't a single downvote.

Engineering

Q&A for professionals and students of engineering

CREATE TABLE #PostVoteCounts 
  (Id int,
   UpVotes int,
   DownVotes int)
go

INSERT INTO #PostVoteCounts 
SELECT
  Votes.PostId,
  SUM(CASE WHEN Votes.VoteTypeId = 2 THEN 1 ELSE 0 END) as UpVotes, 
  SUM(CASE WHEN Votes.VoteTypeId = 3 THEN 1 ELSE 0 END) as DownVotes
FROM Votes
GROUP BY Votes.PostId
go

SELECT TOP 100 Id as [Post Link], Upvotes
FROM #PostVoteCounts 
WHERE DownVotes = 0
ORDER BY UpVotes desc

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results