NovaCart wants to identify its highest-revenue products from completed sales. Write a SQL query to return the top 10 products by total sales revenue.
Requirements
- Use only completed orders when calculating revenue.
- Compute product revenue as
quantity * unit_price from order line items.
- Return each product's
product_id, product_name, and total revenue.
- Sort by total revenue descending, then by
product_id ascending to break ties.
- Return only the top 10 rows.
Table Definitions
products
| column | type | description |
|---|
| product_id | INT | Primary key for each product |
| product_name | VARCHAR(100) | Product name |
| category | VARCHAR(50) | Product category |
orders
| column | type | description |
|---|
| order_id | INT | Primary key for each order |
| customer_id | INT | Customer placing the order |
| order_date | DATE | Order date |
| status | VARCHAR(20) | Order status |
order_items
| column | type | description |
|---|
| order_item_id | INT | Primary key for each order line |
| order_id | INT | References orders.order_id |
| product_id | INT | References products.product_id |
| quantity | INT | Units sold |
| unit_price | DECIMAL(10,2) | Price per unit at purchase time |