Rakuten Marketplace needs a category-level view of its highest-revenue products. Write a PostgreSQL query using a CTE and a window function to identify the top three products in each non-null category based on completed orders.
quantity * unit_price for completed order items only.product_id.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| product_name | VARCHAR(150) | Rakuten Marketplace product name |
| category | VARCHAR(80) | Product category |
| Column | Type | Description |
|---|---|---|
| order_item_idPK | INT | Unique order-item identifier |
| product_id | INT | Referenced product identifier |
| quantity | INT | Number of units purchased |
| unit_price | DECIMAL(10,2) | Price per purchased unit |
| order_status | VARCHAR(20) | Order processing status |