select id, from table where compid = 1 这样查出来的就是14,15,17; 如果再查有一层的话就是select * from table where comid in (select id, from table where compid = 1)但是如果一直有子级怎么办?查询该怎样写
WITH locs(id,name,parent,loclevel) AS ( SELECT id,name,parent,0 AS loclevel FROM tb_loc WHERE parent IS NULL UNION ALL SELECT l.id,l.name,l.parent,loclevel+1 FROM tb_loc l INNER JOIN locs p ON l.parent=p.id )