我的表mytable中这2个字段 一个子节点 一个父节点 organization_id_child organization_id_parent
如果我有这样的数据
organization_id_child organization_id_parent
A 0
B A
C B
D B
E C
F D
我想得到A B C E
A B D F
这样的数据 直接写SQL能实现么?
如果我有这样的数据
organization_id_child organization_id_parent
A 0
B A
C B
D B
E C
F D
我想得到A B C E
A B D F
这样的数据 直接写SQL能实现么?
解决方案 »
- [求助]oracle11g 协议适配器错误
- 如何获取最接近当前时间的记录?
- 表A被select时,对表A的表结构进行修改
- tnsping SID通了.SQLPLUS连,就报错!在线等
- ORA-01536: 超出表空间'USERS'的空间限量,请大家帮帮帮忙啊!
- 用JDK能开发什么项目?
- 往表A中插入数据,若某条记录满足某个条件,就不将该记录插入表A,而是插入表B,可否实现?
- Oracle9i的安装问题,急!!!!!!
- 表、表空间、数据文件、段、范围。。。晕了``
- 数据链的问题
- System.Data.OracleClient 需有 Oracle 用戶端軟體版本 8.1.7 或以上版本
- 字符串翻转的难题
2 select 'A' as organization_id_child ,'o' as organization_id_parent from dual
3 union all
4 select 'B' as organization_id_child ,'A' as organization_id_parent from dual
5 union all
6 select 'C' as organization_id_child ,'B' as organization_id_parent from dual
7 union all
8 select 'D' as organization_id_child ,'B' as organization_id_parent from dual
9 union all
10 select 'E' as organization_id_child ,'C' as organization_id_parent from dual
11 union all
12 select 'F' as organization_id_child ,'D' as organization_id_parent from dual
13 )
14 select replace(sys_connect_by_path(organization_id_child,'*'),'*','') from temp
15 where connect_by_isleaf = 1
16 start with organization_id_parent='o'
17 connect by prior organization_id_child = organization_id_parent
18 ;REPLACE(SYS_CONNECT_BY_PATH(OR
--------------------------------------------------------------------------------
ABCE
ABDFSQL>
SELECT REPLACE(sys_connect_by_path(organization_id_child, ','), ',', '')
FROM (SELECT a.*,
(SELECT COUNT(*)
FROM temp t
START WITH t.organization_id_parent =
a.organization_id_child
CONNECT BY PRIOR
t.organization_id_child = t.organization_id_parent) is_leaf
FROM temp a)
WHERE is_leaf = 0
START WITH organization_id_parent = 'o'
CONNECT BY PRIOR organization_id_child = organization_id_parent;
我的环境是10g的
所以。。呵呵