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;