oracle 加条件 向上递归查询_递归查找某一条件为是的上级id,oracle-sql

展开全部

简单做了几条数据,我这应该是没问62616964757a686964616fe78988e69d8331333332643337题,只是不知道拿到你那会怎么样,有问题直接回复

测试数据create table test

(parent_id int,

id int,

is_rp int,

name varchar2(10));

insert into test values (null,1,1,'aa');

insert into test values (1,2,1,'bb');

insert into test values (1,3,2,'cc');

insert into test values (2,4,1,'dd');

insert into test values (3,5,2,'ee');

insert into test values (4,6,2,'ff');

commit;

执行with t as

(select test.*,level as lv from test

start with id = 6 --这个地方为输入id

connect by prior parent_id=id)

select name from t where exists

(select 1 from

(select is_rp,min(lv) lv from t where is_rp=1 group by is_rp) a

where a.is_rp=t.is_rp and a.lv=t.lv)

你运行一下看看结果

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值