select sum(case when p.posttypeid = 1 -- Q then case when...

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 sum(case when p.posttypeid = 1 -- Q
           then case when v.votetypeid = 2 then 5  -- up
                     when v.votetypeid = 3 then -2 -- down
                end
           else 0
           end
      ) as qrep,
      sum(case when p.posttypeid = 2 -- A
           then case when v.votetypeid = 2 then 10 -- up 
                     when v.votetypeid = 3 then -2 --down
                end
           else 0
           end
      ) as arep ,
      sum(case when p.posttypeid = 2 -- A
           then case when v.votetypeid = 2 then 10 -- up 
                     when v.votetypeid = 3 then -2 --down
                end
           else 0
           end
      )  /
      sum(case when p.posttypeid = 1 -- Q
           then case when v.votetypeid = 2 then 5  -- up
                     when v.votetypeid = 3 then -2 -- down
                end
           else 0
           end
      )  as ratio    
from posts p
inner join votes v on v.postid = p.id

Enter Parameters

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