Q&A for students and teachers of all martial arts
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 posts.OwnerUserId DESC) AS IndexColumn, posts.OwnerUserId, FORMAT(posts.CreationDate, 'yyyy-MM-dd') AS CreationDate, avg(len(body)) AS length FROM posts INNER JOIN TempTable ON posts.OwnerUserId = TempTable.OwnerUserId WHERE PostTypeId=1 AND posts.CreationDate BETWEEN '2020-09-06' AND '2021-02-28' GROUP BY posts.OwnerUserId, FORMAT(posts.CreationDate, 'yyyy-MM-dd'),len(body) ) Select * From FINAL where IndexColumn > 149999 order by IndexColumn