Skip to content
Advertisement

SQL turning rows into columns and populating with values

I’m not quite sure why this table was designed this way, but it’s making it hard to solve my problem. Looking at the data:

What I need help with is to do the following: For each name have the type_name as a column and then fill those columns with the default_value or value.

Like this:

Basically populates from default_value or value depending which one is not null, if both zero then just 0.

Could anyone help me with this as my SQL knowledge is lacking here.

Many thanks!

Advertisement

Answer

You can use PIVOT as follows:

Cheers!!

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