#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;

Exemplo de resposta esperada

É assim que se parece uma resposta correta: ela tem seu próprio número de linhas e não precisa coincidir com as tabelas do esquema.

namecategory
Lamphome
Mugkitchen
Notebookoffice
Entre para enviar

O resultado da sua consulta aparecerá aqui