Q&A about the site for science fiction and fantasy enthusiasts
With a as ( Select CAST(cast(DATEPART(YYYY, p.CreationDate) as float) + cast(DATEPART(MM, p.CreationDate) as float)/12 as float) [Month], p.PostTypeId, p.Score, VoteTypeId, round(1.00*DATEDIFF(day, p.CreationDate, v.CreationDate)/30,0) delay from Votes v join Posts p on p.Id = v.PostId where p.PostTypeId in (1,2) and VoteTypeId in (2,3) ) select SUM(case when VoteTypeId = 2 then 1.00 when VoteTypeId = 3 then -1.00 else 0.00 end) MonthVotes from a group by delay