表结构
create table sys_branch
(
id varchar(64) not null,
parent_id varchar(64),
branch_name varchar(16),
delete_flag int(8),
primary key (id)
);
SELECT ID.level, b.id, b.branch_name as showName, 'branch' as itemType FROM (SELECT @ids AS _ids,
(SELECT @ids := GROUP_CONCAT(id) FROM sys_branch
WHERE FIND_IN_SET(parent_id, @ids)) AS cids, @l := @l + 1 AS LEVEL FROM sys_branch,
(SELECT @ids := #{branchId}, @l := 0) b WHERE @ids IS NOT NULL) id, sys_branch b
WHERE FIND_IN_SET(b.id, ID._ids) ORDER BY LEVEL, id