Ratio of Upvotes to Downvotes Received.

0

Please login or register to vote for this query.

(click on this box to dismiss)

Displays the number of upvotes and downvotes received on questions and answers and their ratio.

Stack Overflow

Q&A for professional and enthusiast programmers

-- Ratio of Upvotes to Downvotes Received.
-- Displays the number of upvotes and downvotes received on questions and answers. 
select
    SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 ELSE 0 END) AS [Up Votes],
    SUM(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE 0 END) AS [Down Votes],
    case when SUM(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE 0 END) = 0 then 999999999 else
    (CAST(SUM(CASE WHEN v.VoteTypeId = 2 THEN 1 ELSE 0 END) AS float) / 
     CAST(SUM(CASE WHEN v.VoteTypeId = 3 THEN 1 ELSE 0 END) AS float)) end 
       AS [Up Votes to Down Votes],
       case posttypeid when 1 then 'Question' WHEN 2 THEN 'Answer' End as posttype,
       count (distinct postid) as distinctpostcount
from
    Votes v 
    inner join Posts p on v.PostId=p.Id
    where posttypeid in (1,2)
group by posttypeid

Enter Parameters

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