递归查询

select code from (
              select t1.code,
              if(find_in_set(parent_code, @pids) > 0, @pids := concat(@pids, ',', `code`), 0) as ischild
              from (select `code`,parent_code from tbl_dept t order by code) t1,
                  (select @pids := #{code}) t2
             ) t3 where  ischild!='0'

  

posted @ 2018-09-25 17:53  咸蛋超人、  阅读(236)  评论(0编辑  收藏  举报