Your question is Top Categories Over Time. 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.
Write a query to identify top-performing product categories over a specific time period.
Use completed orders from January 1, 2025 through March 31, 2025, inclusive. Define performance using total revenue, with units sold and category name used to break ties. Exclude cancelled or returned orders and products without a category.
category, total_revenue, units_sold, order_count, and performance_rankperformance_rank ascending, then category ascending| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Order lifecycle status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-line identifier |
| order_id | INT | Related order identifier |
| product_id | INT | Related product identifier |
| quantity | INT | Number of units purchased |
| unit_price | DECIMAL(10,2) | Price per unit at purchase time |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(100) | Product display name |
| category | VARCHAR(50) | Product category |