pokus

0

Please login or register to vote for this query.

(click on this box to dismiss)

Bicycles Meta

Q&A about the site for people who build and repair bicycles, people who train cycling, or commute on bicycles

WITH user_post_counts AS (
  SELECT 
    u.Id,
    u.DisplayName,
    COUNT(p.Id) AS post_count
  FROM users u
  LEFT JOIN posts p ON u.Id = p.OwnerUserId
  GROUP BY u.Id, u.DisplayName
)
SELECT
  category,
  COUNT(*) AS user_count,
  ROUND(100.0 * COUNT(*) / (SELECT COUNT(*) FROM user_post_counts), 2) AS percentage
FROM (
  SELECT
    CASE
      WHEN post_count = 0 THEN '0'
      WHEN post_count BETWEEN 1 AND 10 THEN '1-10'
      ELSE '>10'
    END AS category,
    Id
  FROM user_post_counts
) AS categorized
GROUP BY category
ORDER BY
  CASE category
    WHEN '0' THEN 1
    WHEN '1-10' THEN 2
    WHEN '>10' THEN 3
  END;

Enter Parameters

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