Upvotes and downvotes on questions and answers for [rust] per day averaged over months since 2013

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 
   min(Votes.CreationDate),
   (sum(case when VoteTypeId = 2 then 1 else 0 end) + 0.0) / DATEPART(day, EOMONTH(MIN(Votes.CreationDate)))
       as 'upvotes per day',
   (sum(case when VoteTypeId = 3 then 1 else 0 end) + 0.0) / DATEPART(day, EOMONTH(MIN(Votes.CreationDate)))
       as 'downvotes per day'
   
from Posts
    -- It would be nicer to only do one inner join of PostTags with
    -- an "or" in the "on" condition. However, that takes significantly
    -- longer for some reason. It's strange really: getting this data
    -- for only questions or only answers is super fast, but combining
    -- them... a lot slower.
    left join PostTags qTags
        on qTags.PostId = Posts.Id 
    left join PostTags aTags 
        on aTags.PostId = Posts.ParentId
    inner join Votes on Votes.PostId = Posts.Id
    
where
    (VoteTypeId = 2 OR VoteTypeId = 3) AND
    (qTags.TagId = 59148 or aTags.TagId = 59148) AND -- that's 'rust'
    Votes.CreationDate > '2013-01-01'

group by 
    DATEPART(month, Votes.CreationDate), 
    DATEPART(year, Votes.CreationDate)
order by min(Votes.CreationDate)

Enter Parameters

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