I have an output of a query as follows:
bid | code | amount |
-----------------------------
2915 | BF | -10700.00 |
2915 | YQ | -300.00 |
2915 | YR | 0.00 |
2915 | YM | 0.00 |
2915 | WO | -153.00 |
2915 | IN | -329.00 |
2915 | K3 | 0.00 |
2915 | CUTE | -50.00 |
-----------------------------
I need to convert the values in code
column to individual columns with column name as corresponding code and amount shall be the value.
bid | BF | YQ | ... | CUTE |
----------------------------------------
2915 | -10700.00| -300.00| ... | -50.00|
The issue is that the result of my initial query has dynamic codes and hence need to generate columns accordingly.
Already tried the following logic but couldn't achieve the goal:
dynamic pivot table using mysql, mysql rows to columns, mysql transpose
All the above links use some expression or the other to generate the columns.
My original resulting rows are result of simple select on multiple joined tables, and has no calculation or expression scope.
Kindly suggest some pointer or hint on how to achieve this.
Many thanks in advance.