One Leader per Category
Each category card must show exactly one most expensive product. If prices tie, the product with the smaller id wins. Fix the report so it returns category and name, one row per category, sorted by category.
Buggy query
SELECT category, name
FROM (
SELECT category, name,
RANK() OVER (PARTITION BY category ORDER BY price DESC) rn
FROM products
) t
WHERE rn = 1
ORDER BY category, name;Exemplu de ieșire așteptată
Așa arată un răspuns corect — numărul său de rânduri îi este propriu, nu trebuie să se potrivească cu tabelele din schemă.
| name | category |
|---|---|
| Lamp | home |
| Mug | kitchen |
| Notebook | office |
Conectează-te pentru a vedea istoricul soluțiilor trimise
Conectează-teConectează-te pentru a folosi Mentorul AI
Conectează-te