Number of posts per one active user

0

Please login or register to vote for this query.

(click on this box to dismiss)

MathOverflow

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(c.CreationDate) AS Umonth,
  CAST(COUNT(DISTINCT c.UserId)+COUNT(DISTINCT c.UserDisplayName) AS Integer) AS UCount
FROM Comments c
---counting users who made at least one comment
GROUP BY eomonth(c.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

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results