/////This question was deleted
Advertisement
Answer
if you want someone to provide you with a complete solution then you will need to supply:
- CREATE TABLE statements for the 3 tables
- INSERT INTO… statements to provide sample data for all 3 tables
However, if you just want a suggestion about how to approach this problem then I would use an UNPIVOT statement to create a view/table that
- holds all the columns in dbo.T_BASE_GEMEINDE_BEVOELKERUNG_JAHR_BEGINN
apart from the “year” columns (J2017, J2018, j2019, …) - adds a single “year” column with values from 2017 to 2050
- adds a single value column to hold the population for each year
By joining your existing tables to this new table/view and grouping by your new “year” column you should achieve what you want