wjbk

导航

Mysql根据当前组织ID查询其下所有子组织ID

select id from (select t1.id,t1.name,if(find_in_set(parent_id, @pids) > 0,@pids:= concat(@pids, ',', id),0) as ischild 
            from (select id,parent_id,name from tableA t order by parent_id,id ) t1,(select @pids:= 参数值) t2 ) t3 where ischild != 0


注:如果识别不了:=符号导致运行报错,在:=前面加两个斜杠(\\:=)

 

posted on 2022-10-11 11:59  wjbk  阅读(47)  评论(0编辑  收藏  举报