Users with highest comments to posts ratio

1

Please login or register to vote for this query.

(click on this box to dismiss)

Aviation

Q&A for aircraft pilots, mechanics, and enthusiasts

;with ccounts_cte AS (
SELECT
  UserId AS uid,
  UserDisplayName AS udn,
  COUNT(Id) AS Ccount
  FROM Comments
  GROUP BY UserId, UserDisplayName
), pcounts_cte AS (
SELECT
  OwnerUserId AS uid,
  OwnerDisplayName AS udn,
  COUNT(Id) AS Pcount,
  SUM(case when PostTypeId = 1 then 1 else 0 end) AS QCount,
  SUM(case when PostTypeId = 2 then 1 else 0 end) AS ACount
  FROM Posts
  GROUP BY OwnerUserId, OwnerDisplayName
)

SELECT TOP(##num?100##)
  c.uid AS [User Link], c.udn AS [DisplayName],
  (CAST(c.CCount AS decimal))/(CAST(p.PCount AS decimal)) AS [Ratio],
  c.CCount AS [Comments],
  p.PCount AS [Posts],
  p.ACount AS [Answers],
  p.QCount AS [Questions]
FROM ccounts_cte c INNER JOIN pcounts_cte p ON ((c.uid=p.uid))
WHERE (PCount>0)
ORDER BY (CAST(c.CCount AS decimal))/(CAST(p.PCount AS decimal)) DESC

Enter Parameters

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