Loft wants to compare user activity across regions using transaction volume. Write a PostgreSQL query that calculates each user's seven-day rolling average of completed transactions and ranks users within their region as of January 10, 2024.
status is completed; exclude pending and cancelled transactions.region by descending rolling average using a window function. Tied averages must receive the same rank.region, user_id, user_name, report_date, rolling_avg, and region_rank, in that order.rolling_avg to four decimal places.region, region_rank, and user_id, placing NULL regions last.| Column | Type | Description |
|---|---|---|
| user_idPK | INTEGER | Unique Loft user identifier |
| user_name | VARCHAR(100) | User's display name |
| region | VARCHAR(50) | User's operating region |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INTEGER | Unique transaction identifier |
| user_id | INTEGER | User associated with the transaction |
| transaction_date | DATE | Date the transaction occurred |
| status | VARCHAR(20) | Transaction processing status |