WITH TempTable AS ( SELECT OwnerUserId, COUNT(CASE WHEN C...

0

Please login or register to vote for this query.

(click on this box to dismiss)

History of Science and Math Meta

Q&A about the site for people interested in the history and origins of science and mathematics

WITH TempTable AS (
    SELECT 
        OwnerUserId,
        COUNT(CASE WHEN CreationDate BETWEEN '2022-09-04' AND '2022-11-27' THEN Id ELSE NULL END) AS CountPeriodA,
        COUNT(CASE WHEN CreationDate BETWEEN '2022-12-04' AND '2023-02-26' THEN Id ELSE NULL END) AS CountPeriodB
    FROM posts
    WHERE PostTypeId = 1
    GROUP BY OwnerUserId
    HAVING 
        COUNT(CASE WHEN CreationDate BETWEEN '2022-09-04' AND '2022-11-27' THEN Id ELSE NULL END) >= 1
        AND 
        COUNT(CASE WHEN CreationDate BETWEEN '2022-12-04' AND '2023-02-26' THEN Id ELSE NULL END) >= 1
),
FINAL As(
SELECT 
    posts.OwnerUserId,
    posts.Id,
    FORMAT(posts.CreationDate, 'yyyy-MM-dd') AS CreationDate
FROM posts 
INNER JOIN TempTable ON posts.OwnerUserId = TempTable.OwnerUserId
WHERE PostTypeId=1 AND CreationDate between '2022-09-04' and '2023-02-26'
GROUP BY posts.OwnerUserId,posts.Id, posts.CreationDate
),FINAL_SELECT AS(
SELECT
    ROW_NUMBER() OVER (ORDER BY FINAL.OwnerUserId DESC) AS IndexColumn,
    FINAL.OwnerUserId,
    PostTags.PostId,
    FINAL.CreationDate,
    Posttags.TagId
From PostTags
INNER JOIN FINAL ON FINAL.Id = PostTags.PostId
GROUP BY FINAL.OwnerUserId,PostTags.PostId,FINAL.CreationDate,Posttags.TagId)

Select * 
from FINAL_SELECT

Enter Parameters

Options:
Switch to main site
loading Hold tight while we fetch your results