Your question is Revenue by Product 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.
Chewy's merchandising team needs a category-level view of revenue from the most recently completed quarter. Assume the reporting date is 2025-04-15, so the last quarter is Q4 2024, from 2024-10-01 through 2024-12-31.
Write a PostgreSQL query that calculates revenue by product category.
status = 'completed' placed during Q4 2024.quantity * unit_price from order items.Uncategorized.| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Current order status |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-line identifier |
| order_id | INT | References orders.order_id |
| product_id | INT | References products.product_id |
| quantity | INT | Number of units purchased |
| unit_price | NUMERIC(10,2) | Price per unit at purchase time |
| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(150) | Product name |
| category | VARCHAR(80) | Product merchandising category |