Search RU
Tasks / SQL / Best product per category
Statement medium

Best product per category

`top_per_category(conn)` returns the single best product in each category: dicts
`{"category", "name", "amount"}`.

Table:

```sql
CREATE TABLE products (category TEXT, name TEXT, amount REAL)
```

The reference implementation uses the window function
`RANK() OVER (PARTITION BY ...)`. Write tests against
`sqlite3.connect(":memory:")`: multiple categories, ordering, an empty table.

sqlwindow-functionssqlite
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

What does `PARTITION BY category` do in a window function, and why is the result
different without it?

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