Comment Distribution

1

Please login or register to vote for this query.

(click on this box to dismiss)

Stack Overflow

Q&A for professional and enthusiast programmers

SELECT
    ISNULL(p.ParentId, p.Id) TopPostId,
    COUNT(DISTINCT c.id) AS CommentCount
  FROM Posts p
  LEFT JOIN Comments c on c.PostId = p.Id
  where p.PostTypeId IN (1,2) -- questions and answers
  GROUP BY ISNULL(p.ParentId, p.Id)
  ORDER BY 1 ASC

Enter Parameters

Options:
Switch to meta site
loading Hold tight while we fetch your results