WITH p AS (SELECT OwnerUserId, COUNT(*) posts FROM Posts ...

0

Please login or register to vote for this query.

(click on this box to dismiss)

The Workplace Meta

Q&A about the site for members of the workforce navigating the professional setting

WITH p AS
(SELECT OwnerUserId, COUNT(*) posts
 FROM Posts
 GROUP BY OwnerUserId)
SELECT u.Id, p.OwnerUserId, p.posts,
(CASE WHEN p.posts IS NULL THEN '1_without_post'
      WHEN p.posts BETWEEN 1 AND 10 THEN '2_one_to_ten_posts'
      WHEN p.posts > 10 THEN '3_more_than_ten_posts'
      END) category
FROM Users u
LEFT JOIN p ON p.OwnerUserId = u.Id
ORDER BY p.posts , u.Id OFFSET 0 ROW FETCH NEXT 20 ROWS ONLY;

Enter Parameters

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