Average Answers Per Question (By Month)

1

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 [Month],
       (CAST(SUM(CASE WHEN PostTypeId = 2 THEN 1 ELSE 0 END) AS FLOAT) / CAST(SUM(CASE WHEN PostTypeId = 1 THEN 1 ELSE 0 END) AS FLOAT)) AS AvgAnswers
FROM
(
    SELECT CAST(
      CAST(DATEPART(YYYY, CreationDate) AS varchar) + '-' + CAST(DATEPART(MM, CreationDate) AS varchar) + '-01'
    AS datetime) [Month], 
    PostTypeId
     
  FROM Posts p
) AS X
GROUP BY [Month]
ORDER BY [Month] ASC

Enter Parameters

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