Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
638 B
8
Indexable
Never
WITH t AS
    (SELECT u.id
    FROM stackoverflow.users u
    JOIN stackoverflow.posts p ON u.id = p.user_id 
    WHERE u.creation_date BETWEEN '2008-09-01' AND '2008-09-30'
          AND p.creation_date BETWEEN '2008-12-01' AND '2008-12-31'
     GROUP BY u.id
     HAVING COUNT(p.id)>0
    )
SELECT COUNT(p.id),
        DATE_TRUNC('month', p.creation_date)::date
FROM stackoverflow.posts AS p
WHERE p.user_id IN (SELECT * FROM t)
   AND DATE_TRUNC('month', p.creation_date) BETWEEN '2008-01-01' AND '2008-12-31'
GROUP BY DATE_TRUNC('month', p.creation_date)::date
ORDER BY DATE_TRUNC('month', p.creation_date)::date DESC;