Write a SQL query using window functions to calculate a rolling 7-day average of portfolio returns by user segment.
Use the provided user and portfolio return data. Exclude returns whose user has no known segment and ignore NULL return values.
segment, return_date, daily_avg_return, and rolling_7_day_avg.segment, then return_date ascending.| Column | Type | Description |
|---|---|---|
| user_idPK | INT | Unique user identifier |
| user_name | VARCHAR(100) | User display name |
| segment | VARCHAR(30) | User investment segment |
| Column | Type | Description |
|---|---|---|
| return_idPK | INT | Unique return record identifier |
| user_id | INT | User associated with the return |
| return_date | DATE | Date of the portfolio return |
| return_pct | NUMERIC(8,5) | Portfolio return expressed as a decimal |