我的表结构:
id | name | parent_id
0 | "name0" | NULL
1 | "name1" | 0
2 | "name2" | 1
...
我需要类似的东西:
id | full_path
2 | "name0|name1|name2"
2
由用户指定;路径的长度未知。怎么用MySQL生成这样的东西?
答案 0 :(得分:-1)
您可以使用此查询:
select id,(select GROUP_CONCAT(CONCAT(name) SEPARATOR '|') as full_path from test )
full_path from test where id=2