Your question is SQL Rolling Average and Ranking. Start with the requirements and the two tables on the right.
Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.
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.| 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 |