ORG_ID 机构ID ORG_NAME 机构名称 ORG_HIGHER 上级机构id
select
ORG_ID
FOMR(
select
t1.ORG_ID,
t1.ORG_NAME,
if(find_in_set(ORG_HIGHER,@pids)>0,
@pids := concat(@pids , ',',ORG_ID),
0) as ischild
from
(select
tt.ORG_ID,
tt.ORG_NAME,
tt.ORG_HIGHER
from
tb_manager t
left join tb_set tt on
t.ORG_ID = tt.ORG_ID
where tt.STATUS !='-1'
order by tt.ORG_HIGHER,
tt.ORG_ID) t1,
(
select
@pids :=
#{orgId}) t2
}t3
where
ischild !=0
or ORG_ID =#{orgId}
//结果如不包含上级机构,去除最后 or ORG_ID =#{orgId}