Write a SQL query using window functions to compute a rolling metric by user over time.
Use settled executions and calculate each user's rolling average PnL over the current execution and the two preceding settled executions. Exclude executions without a settled status.
user_id, user_name, executed_at, execution_id, pnl, and rolling_avg_pnluser_id, executed_at, and execution_id ascending| Column | Type | Description |
|---|---|---|
| user_idPK | VARCHAR(10) | Unique user identifier |
| user_name | VARCHAR(100) | Display name for the user |
| Column | Type | Description |
|---|---|---|
| execution_idPK | INT | Unique execution identifier |
| user_id | VARCHAR(10) | User who generated the execution |
| executed_at | TIMESTAMP | Execution timestamp |
| status | VARCHAR(20) | Execution processing status |
| pnl | DECIMAL(12,2) | Profit or loss from the execution |