Year-over-Year Transaction Growth by Region
Problem statement
For the region named in analysis_params, aggregate total transaction amount by calendar year and calculate year-over-year growth.
The first observed year, a year without the immediately preceding calendar year, or a year whose preceding total is zero must return NULL growth. Otherwise round the percentage to two decimal places.
Table schema
MySQLPostgreSQLPandas
Use the same input data with any supported language. Open the Schema tab in the editor to see the generated SQL setup or Pandas DataFrames.
transactions
| Column | Type | Nullable | Description |
|---|---|---|---|
| transaction_idPK | Integer | No | — |
| region | Text | No | — |
| transaction_date | Date | No | — |
| transaction_amount | Decimal | No | — |
analysis_params
Contains exactly one target region row with param_id 1.
| Column | Type | Nullable | Description |
|---|---|---|---|
| param_idPK | Integer | No | — |
| region | Text | No | — |
Expected result
Your query or function must return these columns.
| Column | Type | Nullable | Description |
|---|---|---|---|
| transaction_year | Integer | No | — |
| total_transaction_amount | Decimal | No | — |
| yoy_growth_percent | Decimal | Yes | — |
Row order: must match exactly. Numeric tolerance: 0.001.
Constraints
analysis_paramscontains exactly one row withparam_id = 1.- Use calendar years from
transaction_date. - Sort by year ascending.