How do you use SQL window functions to calculate running totals or rank users over time?
Use the provided user and transaction data to calculate monthly totals, each user's cumulative total across months, and each user's rank within the month. Include only users with transaction records, including months where their transaction amount is NULL.
user_id, user_name, activity_month, monthly_total, running_total, and monthly_rank.activity_month, monthly_rank, and user_id.activity_month as the first calendar day of each month.NULL amounts as numeric 0.activity_month order.activity_month, monthly_rank, and user_id ascending.monthly_total or running_total; preserve exact numeric results.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| Column | Type | Description |
|---|---|---|
| transaction_idPK | INT | Unique transaction identifier |
| user_id | INT | User associated with the transaction |
| transaction_date | DATE | Date the transaction occurred |
| amount | NUMERIC(12,2) | Transaction amount |