Q&A for professional mathematicians
with counts_cte AS ( SELECT eomonth(p.CreationDate) AS Cmonth, COUNT(p.Id) AS PCount, 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 p GROUP BY eomonth(p.CreationDate) ) , usercounts_cte AS ( SELECT eomonth(p.CreationDate) AS Umonth, CAST(COUNT(DISTINCT p.OwnerUserId)+COUNT(DISTINCT p.OwnerDisplayName) AS Integer) AS UCount FROM Posts p ---counting users who made at least one post GROUP BY eomonth(p.CreationDate) ) SELECT Cmonth, (CAST(PCount AS decimal))/(CAST(UCount AS decimal)) AS [Posts per user], (CAST(QCount AS decimal))/(CAST(UCount AS decimal)) AS [Questions per user], (CAST(ACount AS decimal))/(CAST(UCount AS decimal)) AS [Answers per user] FROM counts_cte INNER JOIN usercounts_cte on Cmonth=Umonth ORDER BY Cmonth