首页 > 其他 > 详细

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

时间:2021-09-06 07:43:08      阅读:16      评论:0      收藏:0      [点我收藏+]
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

 

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

原文:https://www.cnblogs.com/zf-crazy/p/15225762.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!