Your question is Top Five Products by Revenue. 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.
Itlize Global needs a revenue ranking for products sold through its analytics platform. Only completed orders should contribute to reported sales revenue.
Write a PostgreSQL query that returns the five products with the highest sales revenue.
products, order_items, and orders.quantity * unit_price for each line item.completed; treat a missing unit price as zero.product_id as a deterministic tie-breaker.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(150) | Product display name |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| order_date | DATE | Date the order was placed |
| status | VARCHAR(20) | Order processing 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 on the line |
| unit_price | NUMERIC(10,2) | Selling price per unit |