sql:根据子节点向上查找所有父节点
sql:根据子节点向上查找所有父节点
根据子节点向上查找所有父节点:
Sql代码 // 根据物料叶类查询所有父节点(根节点除外) oracle: CString strReletion = " SELECT CHILD_NAME FROM TPOPC03 WHERE 1=1 AND CHILD_NAME != 'ROOT' START WITH CHILD_NAME = @LEAF_CODE CONNECT BY PRIOR PARENT_NAME = CHILD_NAME ORDER BY CHILD_NAME DESC ” db2: CString strReletion ="with par (CHILD_NAME, PARENT_NAME) as ( SELECT CHILD_NAME, PARENT_NAME FROM TPOPC03 WHERE 1=1 AND CHILD_NAME = @LEAF_CODE union all " select t.CHILD_NAME, t.PARENT_NAME from par,TPOPC03 t " where par.PARENT_NAME = t.CHILD_NAME ) select CHILD_NAME from par WHERE par.CHILD_NAME!='ROOT' ";