其他分享
首页 > 其他分享> > 单表递归,查询组织及其自组织的内容信息

单表递归,查询组织及其自组织的内容信息

作者:互联网

select * from system_organization where id = 1
    union all
    select * from system_organization
    where id in (
        select 
        t3.id 
        from (
                select t1.id,
                if(find_in_set(t1.parent_id, @pids) > 0, @pids := concat(@pids, ',', t1.id), 0) as ischild
                from (
                         select id,parent_id from system_organization t where t.status = 1 
                        ) t1,
-- @pids := 1 这里就是赋值 需要查询的父节点id为1的 及其子组织的id (select @pids := 1 id) t2 ) t3 where t3.ischild != 0 ) order by id

 

标签:递归,组织,system,t1,单表,pids,where,id,select
来源: https://www.cnblogs.com/zf-crazy/p/15225762.html