From 0afd00a61987142b9cf43296b72bb073ce43b4f8 Mon Sep 17 00:00:00 2001 From: "Alexis A." Date: Thu, 14 Nov 2024 21:19:24 +0100 Subject: [PATCH] feat(pop): add percent --- .../merge_flux_population_by_admin_level.sql | 4 +++- .../sql/sparte/models/insee/flux_population.sql | 15 ++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/airflow/include/sql/sparte/macros/insee/merge_flux_population_by_admin_level.sql b/airflow/include/sql/sparte/macros/insee/merge_flux_population_by_admin_level.sql index 418a3440d..95001b3a6 100644 --- a/airflow/include/sql/sparte/macros/insee/merge_flux_population_by_admin_level.sql +++ b/airflow/include/sql/sparte/macros/insee/merge_flux_population_by_admin_level.sql @@ -12,7 +12,9 @@ SELECT last_available_year=2020 ) %} sum(population_{{ start_year }}_{{ end_year + 1 }}) - as population_{{ start_year }}_{{ end_year + 1 }} + as population_{{ start_year }}_{{ end_year + 1 }}, + sum(population_{{ start_year }}_{{ end_year + 1 }}) * 100 / sum(population_{{ start_year }}) + as population_{{ start_year }}_{{ end_year + 1 }}_percent {% endcall %} FROM {{ ref('flux_population') }} as flux_population diff --git a/airflow/include/sql/sparte/models/insee/flux_population.sql b/airflow/include/sql/sparte/models/insee/flux_population.sql index e6c50945a..bfbb912ff 100644 --- a/airflow/include/sql/sparte/models/insee/flux_population.sql +++ b/airflow/include/sql/sparte/models/insee/flux_population.sql @@ -6,7 +6,7 @@ }} with flux as ( SELECT - code_commune, + *, -- keep stock columns (population_2010 - population_2009) as population_2009_2010, (population_2011 - population_2010) as population_2010_2011, (population_2012 - population_2011) as population_2011_2012, @@ -24,6 +24,19 @@ with flux as ( ) SELECT code_commune, + population_2009, + population_2010, + population_2011, + population_2012, + population_2013, + population_2014, + population_2015, + population_2016, + population_2017, + population_2018, + population_2019, + population_2020, + population_2021, {% call(start_year, end_year) cumulative_flux( first_available_year=2009, last_available_year=2020