Q&A for professional and enthusiast programmers
SELECT DATEPART(year, p.CreationDate)*100+DATEPART(month, p.CreationDate) AS yearweek, COUNT(DISTINCT p.Id) AS TotalCount, COUNT(DISTINCT CASE WHEN p.Score < 0 THEN p.Id ELSE NULL END) AS DownvotedCount, COUNT(DISTINCT p.ClosedDate) AS ClosedCount, COUNT(DISTINCT CASE WHEN ph.comment='101' THEN p.Id ELSE NULL END) AS DuplicateCount, COUNT(DISTINCT CASE WHEN ph.comment='102' THEN p.Id ELSE NULL END) AS OffTopicCount, COUNT(DISTINCT CASE WHEN ph.comment='103' THEN p.Id ELSE NULL END) AS UnclearCount, COUNT(DISTINCT CASE WHEN ph.comment='104' THEN p.Id ELSE NULL END) AS TooBroadCount, COUNT(DISTINCT CASE WHEN ph.comment='105' THEN p.Id ELSE NULL END) AS OpinionBasedCount FROM Posts p INNER JOIN PostHistory ph ON p.Id = ph.PostId WHERE p.PostTypeId = 1 AND p.CreationDate between '2019-10-01' and '2019-12-31' GROUP BY DATEPART(year, p.CreationDate)*100+DATEPART(month, p.CreationDate)