sql 查询:无限极分类,获取父类下所有子类
如题,一个无限极分类的表,通过一个父类id,如何获取此父类下所有的子类?? 数据表: id,int classname,varchar partid,int如果在sql sever 2005或以上版本可以这样
with a as(
select id,classname,partid from NewClass where id=204
union all
select x.id,x.classname,x.partid from NewClass x,a
where x.partid=a.id)
select * from a
select id,classname,partid from NewClass where id=204
union all
select x.id,x.classname,x.partid from NewClass x,a
where x.partid=a.id)
select * from a
查询结果为: