select eomonth(v.creationdate) as date , sum(case when vo...

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 eomonth(v.creationdate) as date
     , sum(case when votetypeid = 2 then 1 else 0 end) upvotes
     , sum(case when votetypeid = 3 then 1 else 0 end) downvotes
from posts p
inner join votes v on v.postid = p.id
where v.votetypeid in (2, 3)
and posttypeid = 1 -- Question
and v.creationdate <= eomonth(dateadd(m,-1, getdate()))
group by eomonth(v.creationdate)
order by eomonth(v.creationdate)

Enter Parameters

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