Q&A about the site for members of the workforce navigating the professional setting
WITH au AS (SELECT COUNT(Id) all_users FROM Users), p AS (SELECT OwnerUserId, COUNT(*) posts FROM Posts GROUP BY OwnerUserId) SELECT u.Id, p.OwnerUserId, COALESCE(p.posts, 0) count_posts, (CASE WHEN p.posts IS NULL THEN '1_without_post' END) category FROM Users u LEFT JOIN p ON p.OwnerUserId = u.Id ORDER BY count_posts desc, u.Id OFFSET 0 ROW FETCH NEXT 20 ROWS ONLY;