Write a query to find the top three highest-spending merchants per region using window functions.
Calculate each merchant's total order amount across all associated orders. Return only merchants with orders, rank ties by merchant_id ascending, and treat NULL order amounts as zero.
region, merchant_id, merchant_name, total_spent, and merchant_rank.region, then merchant_rank.| Column | Type | Description |
|---|---|---|
| merchant_idPK | INT | Unique merchant identifier |
| merchant_name | VARCHAR(100) | Merchant display name |
| region | VARCHAR(50) | Merchant operating region |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| merchant_id | INT | Merchant associated with the order |
| order_amount | DECIMAL(10,2) | Amount attributed to the merchant for the order |