Users with highest comments to posts ratio


Please login or register to vote for this query.

(click on this box to dismiss)

Physical Fitness

Q&A for physical fitness professionals, athletes, trainers, and those providing health-related needs

;with ccounts_cte AS (
  UserId AS uid,
  UserDisplayName AS udn,
  COUNT(Id) AS Ccount
  FROM Comments
  GROUP BY UserId, UserDisplayName
), pcounts_cte AS (
  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 FULL OUTER JOIN pcounts_cte p ON ((c.uid=p.uid) AND (c.udn=p.udn))
WHERE (PCount>0)
ORDER BY (CAST(c.CCount AS decimal))/(CAST(p.PCount AS decimal)) DESC

Enter Parameters

Switch sites:
loading Hold tight while we fetch your results