Your question is SQL Top 10 by Year. 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.
Expand Energy wants an annual view of product performance in its procurement catalog. Write a PostgreSQL query to find the top 10 products by sales revenue for 2024.
completed status.quantity * unit_price, aggregate revenue by product, and return the top 10 products.product_id as a deterministic tie-breaker.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(100) | Name of the product |
| 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_idPK | INT | Order containing the line item |
| product_idPK | INT | Product sold on the line item |
| quantity | INT | Number of units purchased |
| unit_price | NUMERIC(10,2) | Price per unit at the time of sale |