CREATE OR REPLACE VIEW V_PTREE_TEMP AS
SELECT LEVEL LV, CONNECT_BY_ISLEAF LF, P.PARENTID, P.ID,SYS_CONNECT_BY_PATH(ID, '-')||'-' FULLPATH
FROM BO_PROJECT P
CONNECT BY PRIOR P.ID = P.PARENTID
START WITH P.PARENTID = 0
最后添加-,防止13与139也匹配重复
SELECT * FROM V_PTREE_TEMP T1,BO_PROJECT T2 WHERE
(T2.ID=14715 OR T2.ID=43100 --联合父子项
OR T2.ID=15049 --子项
OR T2.ID=15055 --父项
)
AND T1.FULLPATH LIKE '%-'||T2.ID||'%-'
--这个能统计所有 父子项;
---==============================================----
SELECT * FROM V_PTREE_TEMP T1,BO_PROJECT T2 WHERE
(T2.ID=14715 OR T2.ID=43100 --联合父子项
OR T2.ID=15049 --子项
OR T2.ID=15055 --父项
)
AND T1.FULLPATH LIKE '%-'||T2.ID||'%-'
AND T1.ID<>15055 AND T1.ID<>14715 --去除多余父项
--这个能统计所有 子项;
---==============================================----
SELECT * FROM V_PTREE_TEMP T1,BO_PROJECT T2 WHERE
(T2.ID=14715 OR T2.ID=43100 --联合父子项
OR T2.ID=15049 --子项
OR T2.ID=15055 --父项
)
AND T1.FULLPATH LIKE '%-'||T2.ID||'%-'
AND T1.PARENTID=0
--这个能统计所有 父项;
最后这句才是王道,前面都是浮云
SELECT T1.ID FROM V_PTREE_TEMP T1,BO_PROJECT T2 WHERE
( T2.ID=14715 OR T2.ID=43100 --联合父子项
)
AND T1.FULLPATH LIKE '%-'||T2.ID||'-%' GROUP BY T1.ID
t1.id才是我想要的id,其实都会出笛卡尔积;因此我还要过滤下,父子项的重复关联;
这样不管来什么子的,或父的id,我都能算出全部id;