Q&A for people interested in statistics, machine learning, data analysis, data mining, and data visualization
WITH TempTable AS ( SELECT OwnerUserId, COUNT(CASE WHEN CreationDate BETWEEN '2020-09-06' AND '2020-11-29' THEN Id ELSE NULL END) AS CountPeriodA, COUNT(CASE WHEN CreationDate BETWEEN '2020-12-06' AND '2021-02-28' THEN Id ELSE NULL END) AS CountPeriodB FROM posts WHERE PostTypeId = 1 GROUP BY OwnerUserId HAVING COUNT(CASE WHEN CreationDate BETWEEN '2020-09-06' AND '2020-11-29' THEN Id ELSE NULL END) >= 1 AND COUNT(CASE WHEN CreationDate BETWEEN '2020-12-06' AND '2021-02-28' THEN Id ELSE NULL END) >= 1 ), FINAL AS ( SELECT ROW_NUMBER() OVER (ORDER BY posthistory.UserId DESC) AS IndexColumn, posthistory.UserId, FORMAT(posthistory.CreationDate, 'yyyy-MM-dd') AS CreationDate, Count(posthistory.UserId) AS engagement FROM Posthistory INNER JOIN TempTable ON posthistory.UserId = TempTable.OwnerUserId WHERE posthistory.CreationDate BETWEEN '2020-09-06' AND '2021-02-28' GROUP BY posthistory.UserId, FORMAT(posthistory.CreationDate, 'yyyy-MM-dd') ) SELECT * FROM FINAL