complete transpose a table with dynamic rows and column
0
votes
2
answers
3340
views
I have a mysql database with this structur:
| Name | 2019 | 2020 | 2021 | 2022 | ... |
| --- | --- | --- | --- | --- | --- |
| Name1 | 124 | 98 | 34.5 | NULL | |
| Name2 | 102 | NULL | 34 | NULL | |
| Name3 | 34 | 56 | 97 | 123 | |
| Name4 | NULL | NULL | 34.5 | NULL | |
| ... | | | | | ... |
Every year comes new lines and a column is added.
I want to transpose this table to the structur:
| Year | Name1 | Name2 | Name3 | Name4 | ... |
| --- | --- | --- | --- | --- | --- |
| 2019 | 124 | 102 | 34 | NULL | ... |
| 2020 | 98 | NULL | 56 | NULL | ... |
| 2021 | 34.5 | 34 | 97 | 34.5 | ... |
| 2022 | NULL | NULL | 123 | NULL | ... |
| ... | | | | | ... |
The number of columns and rows are dynamic.
There are many threads with a similar problem (partially transpose with pivot). But I found no solution for this problem.
Thanks for help.
Asked by maphy-psd
(1 rep)
May 31, 2022, 10:30 AM
Last activity: Aug 4, 2025, 05:07 AM
Last activity: Aug 4, 2025, 05:07 AM