SELECT FORMAT(CreationDate, 'yyyy-MM') as Month, COUNT(CA...

0

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
  FORMAT(CreationDate, 'yyyy-MM') as Month,
  COUNT(CASE WHEN PostTypeId = 1 THEN 1 END) as QuestionsPosted,
  COUNT(CASE WHEN PostTypeId = 2 THEN 1 END) as AnswersPosted,
  SUM(CASE WHEN PostTypeId = 2 THEN LEN(Body) - LEN(REPLACE(Body, ' ', '')) + 1 END) as TotalWordsInAnswers
FROM Posts
WHERE
  PostTypeId IN (1, 2) AND
  CreationDate >= DATEADD(month, -12, GETDATE())
GROUP BY FORMAT(CreationDate, 'yyyy-MM')
ORDER BY Month;

Enter Parameters

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