首页 > 解决方案 > MySQL - 行作为具有值的列

问题描述


一段时间以来,我一直在寻找高性能的 MySQL Query 解决方案。希望有人可以帮助我。

我的表看起来像这样:

values_table
___________________________________
| id | col | row | value          |
-----------------------------------
| 1  | 1   | 1   | Test1          |
| 2  | 2   | 1   | Test2          |
| 3  | 1   | 2   | Test3          |
| 3  | 3   | 2   | Test4          |
| 3  | 4   | 3   | Test5          |
-----------------------------------

我想达到以下结果:

_________________________________
| col_1 | col_2 | col_3 | col_4 |
---------------------------------
| Test1 | Test2 | null  | null  |
| Test3 | null  | Test4 | null  |
| null  | null  | null  | Test5 |
---------------------------------

我不知道它可能有多少列,所以它必须是动态的,而不是像静态左连接。这样的事情可能吗?

如果有人可以帮助我,将不胜感激!

谢谢!

标签: mysqlperformancepivot-tablerows

解决方案


推荐阅读