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;
Sampla aschuir a bhfuiltear ag súil leis
Seo é an chuma a bheadh ar fhreagra ceart — tá a líon rónna féin aige, ní gá dó na táblaí scéime a mheaitseáil.
| id | paid_orders |
|---|---|
| 1 | 2 |
| 2 | 1 |
| 3 | 0 |
Logáil isteach chun stair na n-aighneachtaí a fheiceáil
Logáil isteachLogáil isteach chun an Meantóir IS a úsáid
Logáil isteach