|
Finally understand it, it is best to implement it in the program
If there are only two levels, SQL can also be used, if there are unlimited levels, SQL is powerless
In terms of these two levels alone:
SELECT tb.idname, tb_1.idname AS Expr1, tb_2.idname AS Expr2
FROM tb tb_2 RIGHT OUTER JOIN
tb tb_1 ON tb_2.parentid = tb_1.id RIGHT OUTER JOIN
tb ON tb_1.parentid = tb.id
WHERE (tb.parentid = 0) |
|