MySQL View to pivot/transponate data from columns to rows (uniques ids) [closed]

I need a view to transponate / change a existing simple MySQL Table.

There are ID's in every row with specific Parameters for TF, TP, SL, TR, SO in columns.

ID = Primary key and there are no duplicates.

Now I want to change the structure to have a column for each ID and below all the mentioned parameters in rows

Actual Table Structure:

ID    | TF | TP | SL | TR | SO
2034  | H8 | 40  | 20 | 5 | 20  
1023  | D1 | 20  | 10 | 5 | 15

How it should look like with view:

ID | 2034 | 1023
TF |   H8 |  D1  
TP |   40 |  20   
SL |   20 |  10  
TR |    5 |  5   
SO |   20 |  15  

I tried a lot with union all but I could not solve it. Thank you in advance

Source and target



Read more here: https://stackoverflow.com/questions/64898930/mysql-view-to-pivot-transponate-data-from-columns-to-rows-uniques-ids

Content Attribution

This content was originally published by xxvizzorxx at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: