Hi,
I would like to perform a hierarchical query based on a leaf node condition for example; in the below query/results, If the leaf node name starts in 'S' I want to remove this leaf-node and remove the parent providing it doesn't have any other leaf nodes that don't start with 'S', and apply the same criteria up the chain..
In the below example, SMITH starts with S, so I want to remove it, and then remove FORD because it has no other non-'S' child records. SCOTT stays, because its not a leaf node and therefore ADAMS stays too
SELECT empno, LPAD(' ', LEVEL * 2) || ename ename, mgr
FROM emp
START WITH empno = 7839
CONNECT BY PRIOR empno = mgr;
| 1 | 7839 | KING | |
| 2 | 7566 | JONES | 7839 |
| 3 | 7788 | SCOTT | 7566 |
| 4 | 7876 | ADAMS | 7788 |
| 5 | 7902 | FORD | 7566 |
| 6 | 7369 | SMITH | 7902 |
| 7 | 7698 | BLAKE | 7839 |
| 8 | 7499 | ALLEN | 7698 |
| 9 | 7521 | WARD | 7698 |
| 10 | 7654 | MARTIN | 7698 |
| 11 | 7844 | TURNER | 7698 |
| 12 | 7900 | JAMES | 7698 |
| 13 | 7782 | CLARK | 7839 |
| 14 | 7934 | MILLER | 7782 |