WITH filtered_inflation AS
(
SELECT
"year",
inflation_rate
FROM
@kaggle.prasertk_300_years_of_inflation_rate_in_us.inflation_data_1701_2022
),
cumulative_inflation AS
(
SELECT
"year",
inflation_rate,
EXP(SUM(LN(1 + inflation_rate)) OVER (ORDER BY "year")) as comp_inflation
FROM filtered_inflation
WHERE "year" >= 1985
ORDER BY "year"
)
SELECT
fire_data."year",
fire_data."doiagencies",
fire_data."acres",
CAST(REPLACE(REPLACE(fire_data."total", '$', ''), ',', '') AS BIGINT) AS "total_cost",
CAST(REPLACE(REPLACE(fire_data."total", '$', ''), ',', '') AS BIGINT) / cumulative_inflation.comp_inflation * (SELECT comp_inflation FROM cumulative_inflation WHERE "year" = 2020 ) AS "total_cost_normalised",
fire_data."fires",
cumulative_inflation.inflation_rate,
cumulative_inflation.comp_inflation
FROM
@kaggle.kkhandekar_total_wildfires_acres_affected_1983_2020.federal_firefighting_costs_suppression_only AS fire_data
INNER JOIN cumulative_inflation
ON fire_data."year" = cumulative_inflation."year"