WITH FirstAnswers AS ( SELECT Users.Id UserId ,dateadd(week, datediff(week, 0, Convert(Date,Min(Posts.CreationDate))), 0) WeekOf FROM Posts INNER JOIN Users ON Posts.OwnerUserId = Users.Id WHERE PostTypeId = 2 --answer AND Posts.CreationDate > '2011-Jan-01' --There was very little activity prior to this date. Including it skews the graph. GROUP BY Users.Id ), FirstQuestions AS ( SELECT Users.Id UserId ,dateadd(week, datediff(week, 0, Convert(Date,Min(Posts.CreationDate))), 0) WeekOf FROM Posts INNER JOIN Users ON Posts.OwnerUserId = Users.Id WHERE PostTypeId = 1 --question AND Posts.CreationDate > '2011-Jan-01' --There was very little activity prior to this date. Including it skews the graph. GROUP BY Users.Id ) SELECT ISNULL(a.WeekOf,b.WeekOf) As WeekOf , a.AnswerCount, b.QuestionCount FROM ( SELECT WeekOf, Count(UserId) AnswerCount FROM FirstAnswers GROUP BY WeekOf ) a FULL OUTER JOIN ( SELECT WeekOf, Count(UserId) QuestionCount FROM FirstQuestions GROUP BY WeekOf )b ON a.WeekOf = b.WeekOf ORDER BY WeekOf
WITH FirstAnswers AS ( SELECT Users.Id UserId ,dateadd(week, datediff(week, 0, Convert(Date,Min(Posts.CreationDate))), 0) WeekOf FROM Posts INNER JOIN Users ON Posts.OwnerUserId = Users.Id WHERE PostTypeId = 2 --answer AND Posts.CreationDate > '2011-Jan-01' --There was very little activity prior to this date. Including it skews the graph. GROUP BY Users.Id ), FirstQuestions AS ( SELECT Users.Id UserId ,dateadd(week, datediff(week, 0, Convert(Date,Min(Posts.CreationDate))), 0) WeekOf FROM Posts INNER JOIN Users ON Posts.OwnerUserId = Users.Id WHERE PostTypeId = 1 --question AND Posts.CreationDate > '2011-Jan-01' --There was very little activity prior to this date. Including it skews the graph. GROUP BY Users.Id ) SELECT ISNULL(a.WeekOf,b.WeekOf) As WeekOf , a.AnswerCount, b.QuestionCount FROM ( SELECT WeekOf, Count(UserId) AnswerCount FROM FirstAnswers GROUP BY WeekOf ) a FULL OUTER JOIN ( SELECT WeekOf, Count(UserId) QuestionCount FROM FirstQuestions GROUP BY WeekOf )b ON a.WeekOf = b.WeekOf ORDER BY WeekOf