Q&A for professional and enthusiast programmers
DECLARE @refdate DATETIME = DATEFROMPARTS(2022,12,1); SELECT DATEADD(week, MIN(C.WeekNumber), @refdate) AS WeekNumber, CASE WHEN C.PostTypeId = 1 THEN 'asking' ELSE 'answering' END AS Type, COUNT(*) AS UserCount FROM ( SELECT DATEDIFF(week, @refdate, P.CreationDate) AS WeekNumber, P.PostTypeId --MAX(P.OwnerUserId) AS UserId FROM Posts P WHERE P.CreationDate >= @refdate AND P.PostTypeId IN (1,2) GROUP BY P.PostTypeId, P.OwnerUserId, DATEDIFF(week, @refdate, P.CreationDate) HAVING COUNT(*) >= 3 ) C GROUP BY WeekNumber, C.PostTypeId ORDER BY Type, WeekNumber ASC