Your question is SQL Top 3 Products by Category. Start with the requirements and the three tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
Nestlé USA marketing analysts need a category-level view of product performance across brands such as NESCAFÉ, KITKAT, and Stouffer’s. Write a PostgreSQL query that returns the three highest-selling products within every category.
sales_amount.Use ROW_NUMBER() so ties are resolved deterministically by the smaller product_id.
| Column | Type | Description |
|---|---|---|
| category_idPK | INTEGER | Unique product category identifier |
| category_name | VARCHAR(100) | Product category name |
| Column | Type | Description |
|---|---|---|
| product_idPK | INTEGER | Unique product identifier |
| product_name | VARCHAR(150) | Nestlé USA product name |
| category_id | INTEGER | References categories.category_id |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INTEGER | Unique sales record identifier |
| product_id | INTEGER | References products.product_id |
| sales_amount | NUMERIC(12,2) | Revenue associated with the sales record |