instruction: Number of posts per one active user.
response: WITH counts_cte AS (SELECT LAST_DATE_OF_MONTH(p.CreationDate) AS Cmonth, COUNT(p.Id) AS "total_posts", SUM(CASE WHEN p.PostTypeId = 1 THEN 1 ELSE 0 END) AS QCount, SUM(CASE WHEN p.PostTypeId = 2 THEN 1 ELSE 0 END) AS ACount FROM Posts AS p GROUP BY LAST_DATE_OF_MONTH(p.CreationDate)), usercounts_cte AS (SELECT LAST_DATE_OF_MONTH(p.CreationDate) AS Umonth, CAST(COUNT(DISTINCT p.OwnerUserId) + COUNT(DISTINCT p.OwnerDisplayName) AS INT) AS UCount FROM Posts AS p GROUP BY LAST_DATE_OF_MONTH(p.CreationDate)) SELECT Cmonth, ACount, UCount, (CAST(ACount AS FLOAT)) / (CAST(UCount AS FLOAT)) AS "answers_per_user" FROM counts_cte INNER JOIN usercounts_cte ON Cmonth = Umonth ORDER BY Cmonth