Write a SQL query to rank merchants by revenue within each region.
Use the merchants and transactions tables. Revenue is the sum of settled transaction amounts. Include merchants with no settled revenue, and treat their revenue as zero.
region, merchant_id, merchant_name, total_revenue, and revenue_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 |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| merchant_id | INT | Merchant associated with the transaction |
| amount | DECIMAL(12,2) | Transaction amount |
| status | VARCHAR(20) | Transaction processing status |