Q&A for linguists, teachers and learners wanting to discuss the finer points of the Portuguese language
Select [Month], SUM(case when quickVotes < 1 then 1 else 0 end) votes0, SUM(case when quickVotes = 1 then 1 else 0 end) votes1, SUM(case when quickVotes = 2 then 1 else 0 end) votes2, SUM(case when quickVotes = 3 then 1 else 0 end) votes3, SUM(case when quickVotes > 3 then 1 else 0 end) votes4 from ( select [Month], SUM(case when VoteTypeId = 2 then 1.00 when VoteTypeId = 3 then -1.00 else 0.00 end) [quickVotes] from Votes v join ( Select CAST(cast(DATEPART(YYYY, CreationDate) as float) + cast(DATEPART(MM, CreationDate) as float)/12 as float) [Month], Id, CreationDate from Posts ) p on p.Id = v.PostId where DATEDIFF(day, p.CreationDate, v.CreationDate) BETWEEN 0 AND 30 group by [postId],[Month] ) as X group by [Month] order by [Month]