start with....connect by prior 的问题!
id 父id
1 0
2 1
3 1
4 2
5 3
6 3
7 5
比如:如果id=7
要求查询id=7与
(
select id from 表A
start with id=7
connect by prior 父id=id
)
的组合,比如
那么显示出来是:
id
7 7
7 5
7 3
7 1
这个sql 应该如何写呢
[解决办法]
select 7,id from tab01
start with id=7
connect by prior fatid=id;
[解决办法]
这样??
SQL> SELECT 7 ID,7 P_ID FROM DUAL
2 UNION
3 SELECT 7 ID,P_ID FROM SUB_PAR
4 START WITH ID=7
5 CONNECT BY PRIOR P_ID=ID;
ID P_ID
---------- ----------
7 0
7 1
7 3
7 5
7 7
SQL> SELECT * FROM SUB_PAR;
ID P_ID
---------- ----------
1 0
2 1
3 1
4 2
5 3
6 3
7 5
已选择7行。
[解决办法]
love_2008(love2008) ( ) 信誉:100 Blog 加为好友
他的解答和你的结果一致的啊!
SELECT ID,ID as P_ID FROM DUAL
where ID=7
UNION
SELECT 7 ID,P_ID FROM SUB_PAR
START WITH ID=7
CONNECT BY PRIOR P_ID=ID;
和你的表达难道不一样?
[解决办法]
select 7,id from 表A
where 父id is not null
start with id=7
connect by prior 父id=id
7 7
7 5
7 3
7 1
[解决办法]
哦 刚才没看到后面的话 那再看看