不清楚你的表结构,参考一下吧: ID:接点 PID:父节点SQL> select * from testtree;ID PID ---------- ---------- 1 0 2 0 3 1 4 1SQL> select * from testtree a 2 where not exists(select 'x' from testtree connect by prior id = pid start with pid = a.id);ID PID ---------- ---------- 2 0 3 1 4 1
楼上的你的sql 无法执行亚
把你的表结构贴出来看看。如果你是 id,parent_id形式的可以用我上面的,我已经在SQL PLUS测试通过了!上面是贴的测试结果,再整理一下: select * from testtree a where not exists (select 'x' from testtree connect by prior id = pid start with pid = a.id)如果你是id,child_id的话,可以把叶子节点的child_id 设成null,那直接就可以来判断的啊
ID:接点
PID:父节点SQL> select * from testtree;ID PID
---------- ----------
1 0
2 0
3 1
4 1SQL> select * from testtree a
2 where not exists(select 'x' from testtree connect by prior id = pid start with pid = a.id);ID PID
---------- ----------
2 0
3 1
4 1
select * from testtree a
where not exists (select 'x' from testtree
connect by prior id = pid
start with pid = a.id)如果你是id,child_id的话,可以把叶子节点的child_id 设成null,那直接就可以来判断的啊