Given a table of financial metrics, write a query using window functions to calculate a rolling average of debt-to-equity ratios.
Use a three-reporting-period rolling average separately for each issuer, including the current row and two preceding chronological rows. Include rows with NULL ratios, allowing the average calculation to follow PostgreSQL NULL behavior.
issuer_id, reporting_date, debt_to_equity_ratio, and rolling_avg_debt_to_equity.issuer_id, then reporting_date ascending.| Column | Type | Description |
|---|---|---|
| metric_idPK | INT | Unique financial metric record identifier |
| issuer_id | VARCHAR(20) | Identifier for the rated issuer |
| reporting_date | DATE | Period-ending date for the metric |
| debt_to_equity_ratio | DECIMAL(10,4) | Issuer debt-to-equity ratio for the reporting period |