You are given monthly financial data and asked to identify the main drivers of performance by business segment. Write a PostgreSQL query that joins the tables, calculates revenue, cost, and gross profit by segment for a given month, and classifies each segment as growth, stable, or decline based on gross profit margin.
| Column | Type | Description |
|---|---|---|
| segment_idPK | INT | Primary key for the segment |
| segment_name | VARCHAR(100) | Business segment name |
| region | VARCHAR(50) | Operating region |
| Column | Type | Description |
|---|---|---|
| fact_idPK | INT | Primary key for the financial fact row |
| segment_id | INT | References the segment being measured |
| month_end | DATE | Month-end reporting date |
| revenue | NUMERIC(12,2) | Reported revenue for the period |
| cost | NUMERIC(12,2) | Reported cost for the period |
| is_adjusted | BOOLEAN | Whether the record has been adjusted |