I need to transpose data as shown in the tables below. I will need this to be done dynamically on any number of columns (they can have from 1 up to 100), and i also only want to transpose some of the data. Note that there can be up to millions of rows.
we have new data like this (read from a csv into temp table):
id | name | field1 | field2 | field3
1 | igig | a | b | cde
2 | ihiuh | gf | hi | pl
3 | pio | zsfs | oij | ugu
4 | xrxf | iuhi | vxz | pkm
5 | rwtre | xrsd | as | jhb
we need to do query magic to transpose results like this:
id | column_name | value
1 | name | igig
1 | field1 | a
1 | field2 | b
1 | field3 | cde
2 | name | ihiuh
2 | field1 | gf
2 | field2 | hi
...
we want to join this new result set with another table.