WITH cp AS (SELECT u.Id, p.OwnerUserId, p.posts, (CASE WH...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Operations Research Meta

Q&A about the site for operations research and analytics professionals, educators, and students

WITH cp AS
(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 (SELECT OwnerUserId, COUNT(*) posts
          FROM Posts
          GROUP BY OwnerUserId) p 
          ON p.OwnerUserId = u.Id)
SELECT cp.Id, cp.posts, cp.category
FROM cp


ORDER BY cp.posts , cp.Id OFFSET 0 ROW FETCH NEXT 20 ROWS ONLY;

Enter Parameters

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