Distribution of number of votes on questions

0

Please login or register to vote for this query.

(click on this box to dismiss)

History of Science and Math

Q&A for people interested in the history and origins of science and mathematics

-- compute for each question how many votes it has 
--(question means posttypeid = 1)
with a as (
   Select p.Id, 
          Count(v.PostId) n_votes
   from Votes v join PostsWithDeleted p 
   on v.PostId = p.Id
   where p.PostTypeId in (1) 
     and v.VoteTypeId in (2,3)
     and Year(p.CreationDate) = 2012
   group by p.Id
),

--- add posts with zero counts which are not being counted by the scan on the votes table
b as (
   select pp.Id, 
          Case 
             When n_votes > 0 then n_votes
             else 0 
          end  n_votes
   from a full outer join PostsWithDeleted pp 
   on a.Id = pp.id
   where pp.PostTypeId in (1)
     and Year(pp.CreationDate) = 2012
),

--- create histogram of counts
c as (
   select n_votes, count(n_votes) counts
   from b 
   group by n_votes
),

--- create histogram of percentage
d as (
   select n_votes, 100.0*counts/sum(counts) over() percentage
   from c
)

--- display first values

select n_votes, percentage 
from d
where n_votes < 11
order by n_votes

Enter Parameters

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