ResMed’s myAir analytics team wants to identify the highest-usage users in each geographic region. Write a PostgreSQL query that ranks users by their total completed therapy duration.
myair_usage_sessions using user_id.session_status = 'completed' and a non-null, non-negative duration_minutes value.user_id. Include the region, user ID, total duration, and regional rank.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique myAir user identifier |
| region | VARCHAR(50) | Geographic region assigned to the user |
| Column | Type | Description |
|---|---|---|
| session_idPK | INTEGER | Unique usage session identifier |
| user_id | INTEGER | Associated user identifier |
| session_date | DATE | Date on which the therapy session occurred |
| duration_minutes | INTEGER | Therapy usage duration in minutes |
| session_status | VARCHAR(20) | Processing status of the usage session |