Your question is Top 3 Products by Category. Start with the requirements and the two 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.
Rakuten Marketplace needs a category-level view of its highest-revenue products. Write a PostgreSQL query using a CTE and a window function to identify the top three products in each non-null category based on completed orders.
quantity * unit_price for completed order items only.product_id.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(150) | Rakuten Marketplace product name |
| category | VARCHAR(80) | Product category |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-item identifier |
| product_id | INT | Referenced product identifier |
| quantity | INT | Number of units purchased |
| unit_price | DECIMAL(10,2) | Price per purchased unit |
| order_status | VARCHAR(20) | Order processing status |