当前位置:Gxlcms > mysql > DB2递归SQL根据当前机构查询所有下属机构树

DB2递归SQL根据当前机构查询所有下属机构树

时间:2021-07-01 10:21:17 帮助过:49人阅读

CREATE TABLE UNTECK_ORGANIZATION ( ID BIGINT NOT NULL, LEVEL_ INTEGER, NAME VARCHAR(64), AREACODE VARCHAR(8), ORGSEQ VARCHAR(128), PARENTID BIGINT, THESORT INTEGER, DESCN VARCHAR(256), DEL_FLAG INTEGER, CREATE_TIME TIMESTAMP, CREATE_USER V

CREATE TABLE UNTECK_ORGANIZATION (
ID BIGINT NOT NULL,
LEVEL_ INTEGER,
NAME VARCHAR(64),
AREACODE VARCHAR(8),
ORGSEQ VARCHAR(128),
PARENTID BIGINT,
THESORT INTEGER,
DESCN VARCHAR(256),
DEL_FLAG INTEGER,
CREATE_TIME TIMESTAMP,
CREATE_USER VARCHAR(64),
UPDATE_TIME TIMESTAMP,
UPDATE_USER VARCHAR(64),
CODE VARCHAR(64),
ADDRESS VARCHAR(255),
CELLPHONE VARCHAR(24),
ORGTYPE VARCHAR(20),
PRIMARY KEY (ID) );

with temptab(ID,NAME,CODE,PARENTID) as

(
select a.ID,a.NAME,a.CODE,a.PARENTID
from UNTECK_ORGANIZATION a
where a.ID = 3413585099
union all
select sub.ID,sub.NAME,sub.CODE,sub.PARENTID
from UNTECK_ORGANIZATION sub, temptab super
where sub.PARENTID = super.ID
)
select ID,NAME,CODE,PARENTID from temptab

人气教程排行