日期:2014-05-17 浏览次数:20803 次
with t as ( select 'A' parent1, 'B' child1 from dual union all select 'B' , 'C' from dual union all select 'B' , 'D' from dual union all select 'D' , 'E' from dual union all select 'C' , 'F' from dual union all select 'M' , 'B' from dual union all select 'M' , 'L' from dual union all select 'M' , 'N' from dual union all select 'L' , 'Z' from dual union all select 'Z' , 'N' from dual union all select 'N' , 'S' from dual )select distinct r,child1 from ( select t.*,connect_by_isleaf leaf,connect_by_root parent1 r from t start with t.parent1 in ('A','Z','M') connect by prior t.child1=t.parent1 ) a where a.leaf=1 order by 1
------解决方案--------------------
CREATE TABLE A ( PARENT VARCHAR2(10), CHILD VARCHAR2(10) ); 统计sql: select parent,wm_concat(CHILD) from A t where t.parent in ('A','Z','M') group by parent order by parent 查询结果: A B M B,N,L Z N