#975

Keep Users Without Payments

The user report must show how many orders with status = 'paid' each user has. The current version dropped users with no paid orders, but they must remain with 0. Return id and paid_orders, sorted by id.

Buggy query
SELECT u.id, COUNT(o.id) AS paid_orders
FROM users u
LEFT JOIN orders o ON o.user_id = u.id
WHERE o.status = 'paid'
GROUP BY u.id
ORDER BY u.id;

Expected output sample

This is what a correct answer looks like — its row count is its own, it doesn't have to match the schema tables.

idpaid_orders
12
21
30

Your query result will appear here