I'm using the dataset bigquery-public-data.world_bank_global_population.population_by_country
, and I'd like to convert this data into something along the lines of country, country_code, year, population.
country | country_code | year_1960 | ... | year_2018 |
---|---|---|---|---|
World | WLD | 3032019978 | ... | 7594270356 |
Canada | CAN | 17909009 | ... | 37058856 |
to...
country | country_code | year | population |
---|---|---|---|
World | WLD | 1960 | 3032019978 |
World | WLD | 2018 | 7594270356 |
Cananda | CAN | 1960 | 17909009 |
Canada | CAN | 2018 | 37058856 |
The trouble for me is there are 264 unique rows, and 60 'year' columns'.
I suspect there's a way to transpose the data without using 60 case when
statements (I'm not even sure that many are allowed). I was able to get the results I was looking for using a couple of UDFs based on this post, but I'm hoping there's a more elegant way that doesn't rely on those.