Write a SQL query using window functions to rank customers or events within each group and return the top record per group.
Use the provided customers and events tables. Calculate each active customer's total value from completed events, rank customers within their region, and resolve ties by the lowest customer_id.
region, customer_id, customer_name, total_event_value, and customer_rank.region.| Column | Type | Description |
|---|---|---|
| customer_idPK | INT | Unique customer identifier |
| customer_name | VARCHAR(100) | Customer display name |
| region | VARCHAR(50) | Customer region |
| is_active | BOOLEAN | Whether the customer is active |
| Column | Type | Description |
|---|---|---|
| event_idPK | INT | Unique event identifier |
| customer_id | INT | Customer associated with the event |
| event_date | DATE | Date of the event |
| event_status | VARCHAR(20) | Event processing status |
| event_value | NUMERIC(10,2) | Value attributed to the event |