#978

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;

Esempio di output atteso

Ecco come appare una risposta corretta — il suo numero di righe è a sé stante, non deve corrispondere alle tabelle dello schema.

namecategory
Lamphome
Mugkitchen
Notebookoffice

Il risultato della tua query apparirà qui