我可以在mysql中选择并连接树的所有父ID吗?

时间:2015-12-03 16:15:52

标签: mysql hierarchy

我有这样的表:

+--------+---------+
| Id     | Pid     |
+--------+---------+
|      1 |       0 |
|      2 |       1 |
|      3 |       2 |
|      4 |       3 |
|      5 |       3 |
|      6 |       2 |
+--------+---------+

我想选择记录的所有父ID,并将它们连接起来:

+--------+---------+
| ID     | pidList |
+--------+---------+
|        |         |
|      1 |0        |
|      2 |1,0      |
|      3 |2,1,0    |
|      4 |3,2,1,0  |
|      5 |3,2,1,0  |
|      6 |2,1,0    |
+--------+---------+

0 个答案:

没有答案