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

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

 

上一篇:部署脚本不会写? 抄作业~


下一篇:实验3:GVRP的配置