Top 2 Products per Category
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_id | category | name | sales |
|---|
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