Write a complex SQL query to find the top 3 items within a top 3 category for Mastercard transaction data.
Use the provided product and transaction data. Calculate rankings by total transaction amount, include exactly three items per selected category when available, and use deterministic tie-breaking.
category_name, category_total, item_name, item_total.| Column | Type | Description |
|---|---|---|
| product_idPK | INT | Unique product identifier |
| item_name | VARCHAR(100) | Product or item name |
| category_name | VARCHAR(100) | Product category |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique Mastercard transaction identifier |
| product_id | INT | Referenced product identifier |
| amount | DECIMAL(12,2) | Transaction amount in the reporting currency |