Your question is Top 5 Products by Revenue. Start with the requirements and the two 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.
Closer Consulting needs a revenue ranking for products sold through its analytics operations. Write a PostgreSQL query to return the five products with the highest revenue from completed sales.
status = 'completed' and calculate revenue as quantity * unit_price.products table to display the product name.product_id as a secondary sort for deterministic results.| Column | Type | Description |
|---|---|---|
| product_idPK | INTEGER | Unique product identifier |
| product_name | VARCHAR(100) | Product name |
| category | VARCHAR(50) | Product category |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INTEGER | Unique sale identifier |
| product_id | INTEGER | Product identifier associated with the sale |
| quantity | INTEGER | Number of units sold |
| unit_price | NUMERIC(12,2) | Price charged per unit |
| status | VARCHAR(20) | Sale processing status |