Eventually need to generate the root directory & gt; One level & gt; The secondary directory & gt; Three directories & gt; .> The bottom directory
Such as table: TABLE_A
Fields: ID, NAME, PARENT_ID
1 the root directory null
2 one level 1
4 secondary directory 2
10 three directories 4
12 directory the bottom 10
CodePudding user response:
http://blog.csdn.net/qq12547345/article/details/72630285You can refer to the man's blog,
Using the function find_in_set
CodePudding user response:
SELECT @ v FROM (
SELECT @ v:=CONCAT_WS (' & gt; ', SELECT the NAME FROM TABLE_A WHERE PARENT_ID & lt;=> @ id) as v,
@ id:=(SELECT id FROM TABLE_A WHERE PARENT_ID & lt;=> @ id)
The FROM TABLE_A A, (SELECT @ v:=null, @ id:=null) _r
) A LIMIT 1