Questions and Answers per Month

0

Please login or register to vote for this query.

(click on this box to dismiss)

Ask Ubuntu

Q&A for Ubuntu users and developers

select [Month], 
       sum(case when PostTypeId = 1 and 0 < 1 then 1 else 0 end) All_Questions,
       sum(case when PostTypeId = 1 and AnswerCount > 0 then 1 else 0 end) Questions_with_Answers,
       cast(sum(case when PostTypeId = 2 and 0 < 1 then Score else 0 end) /
       sum(case when PostTypeId = 2 and 0 < 1 then 1 else 0 end) as Decimal(6,3))
       ScoreRatio
from
(
  select CAST(
      cast(DATEPART(YYYY, CreationDate) as varchar) + '-' + cast(DATEPART(MM, CreationDate) as varchar) + '-01'
    as datetime) [Month], 
    AnswerCount, PostTypeId, Score
     
  from Posts p
  where ClosedDate is NULL
) as X
group by [Month]
order by [Month] asc

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results