MySQL递归

 查询用户ID为1的所有子用户:

 

select  id,
        name,
        parent
from    (select * from tablename
         order by parent, id) tablename,
        (select @pv := '1') initialisation
where   find_in_set(parent, @pv) > 0
and     @pv := concat(@pv, ',', id)

 

posted @ 2022-02-09 15:01  _迷途  阅读(35)  评论(0编辑  收藏  举报