AnalystPath

Top 2 Products per Category

SQLMediumMid levelAmazon~15 min

Problem

**[Asked at Amazon]**

For each category, return the **top 2 products by sales**.

Return `category`, `name`, `sales`, ordered by category then sales descending.

Tables

Example rows — the live problem includes the full dataset.

products
product_idcategorynamesales

Expected output

Your answer should return 6 rows with the columns category, name, sales.

Starter code (SQL)

SELECT *
FROM products;

Solve this SQL question free

Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.

Solution & explanation

Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.

Sign up free to unlock

Related SQL questions