Code declare@patidintset@patid=0---已知父节点ID ; ----必须 withtemp (id ,parentid) as ( select listid,parentid from TB_list where parentid =@patid unionall select b.listid,b.parentid fromtemp A ,TB_list B where b.parentid = a.id ) select id,parentid fromtemp