Find all question posts with the tag ‘python’ on stack overflow, along with all their replies and comments, including the user who posted the question and reply, and then assign these posts to the corresponding year and month based on when they were posted to calculate the number of relevant users for each month and year, where relevant users are the users who posted the question and reply. users. Below is my code, after running the result is empty, can you help me point out the problem and the correct code?
SELECT
DATEPART(yyyy, p.CreationDate) AS Year,
DATEPART(mm, p.CreationDate) AS Month,
COUNT(DISTINCT CASE WHEN p.PostTypeId = 1 THEN p.OwnerUserId ELSE NULL END) AS Questioning,
COUNT(DISTINCT CASE WHEN p.PostTypeId = 2 THEN p.OwnerUserId ELSE NULL END) AS Answering,
COUNT(DISTINCT p.OwnerUserId) AS RelevantUsers
FROM
Posts p
JOIN
PostTags pt ON p.Id = pt.PostId OR p.ParentId = pt.PostId
JOIN
Tags t ON pt.TagId = t.Id
WHERE
t.TagName = 'python'
GROUP BY
DATEPART(yyyy, p.CreationDate),
DATEPART(mm, p.CreationDate)
ORDER BY
Year, Month;