Distribution of the number of comments per post

0

Please login or register to vote for this query.

(click on this box to dismiss)

Interpersonal Skills

Q&A for people looking to improve their interpersonal communication skills

DECLARE @TotalQuestions AS Int = (SELECT Count(*) FROM Posts WHERE PostTypeId = 1)
DECLARE @TotalAnswers AS Int = (SELECT Count(*) FROM Posts WHERE PostTypeId = 2)

SELECT
  CommentCount AS [Number of comments],
  Count(*) * 100.0 / (@TotalQuestions + @TotalAnswers) AS [% Posts],
  Count(Nullif(PostTypeId, 2)) * 100.0 / @TotalQuestions AS [% Questions],
  Count(Nullif(PostTypeId, 1)) * 100.0 / @TotalAnswers AS [% Answers],
  Count(Nullif(PostTypeId, 2)) AS [# Questions],
  Count(Nullif(PostTypeId, 1)) AS [# Answers]
FROM Posts
WHERE (PostTypeId = 1 OR PostTypeId = 2)
GROUP BY CommentCount
ORDER BY CommentCount ASC

Enter Parameters

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