I have a table which has only one row like below,
Here I want to convert the column names to one column and the row into another column, with the column names converted to some predefined numbers as below (A->1E9, B->1E8, … E->1E5),
I can’t use pivot commands or else. Is there any good way to do this transform? Thanks!!
2
Answers
Use
UNION
Here is one way to unpivot your data using a lateral join:
The lateral join is more efficient than
union
to solve the question, because it scans the table only once – although if your table has just one row then obviously it won’t make a visible difference.The feature is available in MySQL starting version 8.0.14.