Your question is Top Product Lines 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.
NetApp's BI team needs a ranked view of product-line performance for completed sales recorded during 2025. Write a PostgreSQL query to identify the top three NetApp product lines by revenue.
product_lines to sales using product_line_id.status = 'completed' and a sale_date in calendar year 2025.units_sold * unit_price, treating NULL numeric inputs as zero.product_lines includes ONTAP, AFF, FAS, StorageGRID, BlueXP, Keystone, ASA, and Cloud Volumes ONTAP. sales contains multiple rows per product line, cancelled and out-of-period sales, NULL values, and one orphaned product-line ID.
| Column | Type | Description |
|---|---|---|
| product_line_idPK | INT | Unique product-line identifier |
| product_line_name | VARCHAR(80) | NetApp product-line name |
| Column | Type | Description |
|---|---|---|
| sale_idPK | INT | Unique sale identifier |
| product_line_id | INT | Logical reference to the product line |
| units_sold | INT | Number of units sold |
| unit_price | NUMERIC(12,2) | Price per unit |
| sale_date | DATE | Date on which the sale was recorded |
| status | VARCHAR(20) | Sale processing status |