我就不吃芹菜

导航

 

表结构

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

 

posted on 2019-05-21 09:32  我就不吃芹菜  阅读(3896)  评论(0编辑  收藏  举报