Order search results by votes (not by score!)

1

Please login or register to vote for this query.

(click on this box to dismiss)

https://meta.stackoverflow.com/questions/388169

Physical Fitness Meta

Q&A about the site for physical fitness professionals, athletes, trainers, and those providing health-related needs

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
     , min(p.score) score
from votes v
inner join posts p on p.id = v.postid
where votetypeid in (2, 3) -- upmod, downmod
and posttypeid in (1, 2) -- Q, A
and ('##userid?674039##' = 0 or owneruserid = ##userid?674039##)
group by postid
order by (select max(val) 
          from ( select sum(case when votetypeid = 2 then 1 else 0 end) val
                union
                select sum(case when votetypeid = 3 then 1 else 0 end)
          ) alldata
         ) desc

Enter Parameters

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