Q&A for scholars and enthusiasts of literature
DECLARE @StartTime DATETIME = convert(DATETIME, '##StartTime?2000/01/01##') DECLARE @EndTime DATETIME = dateadd(day,0,getdate()) select q.MonthOf, sum(q.Answered)/cast(count(*) as decimal) as 'Answered', sum(q.Closed)/cast(count(*) as decimal) as 'Closed' from(select dateadd(day, 1-datepart(day,p.CreationDate), convert(date,p.CreationDate)) as 'MonthOf', cast(case when p.AnswerCount > 0 then 1 else 0 end as tinyint) as 'Answered', cast(case when p.ClosedDate is not null then 1 else 0 end as tinyint) as 'Closed' from Posts as p where p.PostTypeId = 1 and p.CreationDate > @StartTime and p.CreationDate < @EndTime ) q group by q.MonthOf order by q.MonthOf