Search RU
Tasks / SQL / Customers without orders and their totals
Statement medium

Customers without orders and their totals

`customers_with_totals(conn)` returns every customer with their total and order
count:

```python
{"name": str, "total": number, "orders": int}
```

Schema:

```sql
CREATE TABLE customers (id INTEGER PRIMARY KEY, name TEXT)
CREATE TABLE orders (id INTEGER PRIMARY KEY, customer_id INTEGER, amount REAL)
```

Requirements: customers without orders are included too (`total = 0`,
`orders = 0`), sorted by total descending.

Write tests on in-memory sqlite: a customer without orders, several orders, an
empty database.

sqlleft-joinnullsaggregation
test_solution.py Python 3.14
AI mentor

The AI mentor is available after you log in: it sees your attempt history and does not spend resources on anonymous requests.

Log in and ask
Hints 1 of 3 unlocked · attempts: 0
Hint 1

Is a customer without orders a row or an absence of a row? The answer decides
between `JOIN` and `LEFT JOIN`.

Hint 2 — unlocks after 1 attempt
Hint 3 — unlocks after 3 attempts