select top 1000 postid as [Post Link] , sum(case when vot...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

select top 1000 
  postid as [Post Link]
, sum(case when votetypeid = 2 then 1 else 0 end) [upvotes]
, sum(case when votetypeid = 3 then 1 else 0 end) [downvotes]
, sum(case when votetypeid = 2 then 1 else 0 end) - sum(case when votetypeid = 3 then 1 else 0 end) [score]
, count(*) [total]
from votes v
group by postid
order by downvotes desc 
       , score

Enter Parameters

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