Write a SQL query to join orders, customers, and payments and calculate monthly revenue by region.
Use completed payments with a non-NULL payment timestamp. Treat a NULL customer region as Unknown and exclude payments without matching orders or customers.
revenue_month, region, and monthly_revenue.paid_at; order by revenue_month ascending, then region ascending.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer name |
| region | VARCHAR(50) | Customer sales region |
| Column | Type | Description |
|---|---|---|
| order_idPK | INT | Unique order identifier |
| customer_id | INT | Customer associated with the order |
| ordered_at | TIMESTAMP | Order creation timestamp |
| Column | Type | Description |
|---|---|---|
| payment_idPK | INT | Unique payment identifier |
| order_id | INT | Order associated with the payment |
| paid_at | TIMESTAMP | Payment completion timestamp |
| amount | NUMERIC(12,2) | Payment amount |
| status | VARCHAR(40) | Payment processing status |