Skip to content
Advertisement

BigQuery SQL reshape four columns into one column with name of column as value

I currently have a table that looks like:

Is it possible to reshape my data into:

Where the name of the column equal to 1 becomes the value of code in the new reshaped dataset. I have already presorted the dataset such that there will be no case where more than one column is equal to 1.

Advertisement

Answer

Consider below approach

if applied to sample data in your question – output is

enter image description here

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement