Paid Orders per Buyer
Analytics needs, for each buyer who has orders with status = 'paid', the number of those orders. Replace the raw repeated-row approach with one row per user_id. Return user_id and paid_count, sorted by user_id.
Original query
SELECT DISTINCT o.user_id, (SELECT COUNT(*) FROM orders o2 WHERE o2.user_id = o.user_id AND o2.status='paid') AS paid_count FROM orders o WHERE o.status='paid' AND o.user_id IS NOT NULL ORDER BY o.user_id
Kampjun tal-output mistenni
Dan hu kif tidher tweġiba korretta — l-għadd tar-ringieli huwa tiegħu stess, m'għandux għalfejn jaqbel mat-tabelli tal-iskema.
| user_id | paid_count |
|---|---|
| 1 | 2 |
| 2 | 1 |
Idħol biex tara l-istorja tas-sottomissjonijiet
IdħolIdħol biex tuża l-Mentor tal-AI
Idħol