SELECT Category, ROUND(100.*COUNT(DISTINCT(Id))/(SELECT C...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Game Development Meta

Q&A about the site for professional and independent game developers

SELECT
  Category,
  ROUND(100.*COUNT(DISTINCT(Id))/(SELECT COUNT(DISTINCT(Id)) FROM USERS), 2) AS Percentage,
  COUNT(DISTINCT(Id)) AS 'Count'
FROM (
  SELECT
    Users.Id,
    CASE
      WHEN COUNT(p.Id) = 0 THEN '0'
      WHEN COUNT(p.Id) >= 1 AND COUNT(p.Id) <= 10 THEN '1-10'
      ELSE '>10'
    END AS Category
  FROM Users
  LEFT JOIN Posts p ON p.OwnerUserId = Users.Id
  GROUP BY Users.Id
) Prep
  GROUP BY Category
  ORDER BY CASE
    WHEN Category = '0' THEN 0
    WHEN Category = '1-10' THEN 0
    WHEN Category = '>10' THEN 0
  END

Enter Parameters

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