一条语句实现不了。得分步: 1)select id,parent_id,name from table where parent_id = 0;//查出父节点“张三” 2)select id,parent_id,name from table where parent_id = 张三ID;//查出一级子类 3)select id,parent_id,name from table where parent_id = 张三以及子类的ID;//查出二级子类(循环或者用in) 4)采用第三步方法插叙三级、四级子类。
1)select id,parent_id,name from table where parent_id = 0;//查出父节点“张三”
2)select id,parent_id,name from table where parent_id = 张三ID;//查出一级子类
3)select id,parent_id,name from table where parent_id = 张三以及子类的ID;//查出二级子类(循环或者用in)
4)采用第三步方法插叙三级、四级子类。