Write a SQL query to compare metrics across time periods and highlight changes month over month.
Use the provided metric definitions and observations. Include metrics with no prior month for comparison, and avoid calculating a percentage change when the prior value is missing or zero.
metric_name, month, metric_value, prior_month_value, change_value, and change_percent.metric_name and month ascending, and return NULL for unavailable comparisons.| Column | Type | Description |
|---|---|---|
| metric_idPK | INT | Unique identifier for the metric |
| metric_name | VARCHAR(100) | Display name of the metric |
| unit | VARCHAR(30) | Unit used to interpret the metric value |
| Column | Type | Description |
|---|---|---|
| observation_idPK | INT | Unique observation identifier |
| metric_id | INT | Metric identifier associated with the observation |
| observed_at | DATE | Date on which the metric was observed |
| metric_value | DECIMAL(12,2) | Observed metric value |