I had perceived an uptick in new reviewers around here, and I wanted to see if the data backed that observation up. It's been a while since I've written any SQL, so this was a nice little exercise in using the Stack Exchange Data Explorer.
The query finds the first question and first answer from every user, and then groups those first posts by week. It turns out that I was right, but the growth of first questions is outpacing the growth of first answers.
The query feels repetitive and I'm not a huge fan of the Full Outer Join
.
Is there a better way to write this?
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