-3

假设以下是层次结构: 在此处输入图像描述

我正在通过5,所以我除了 5,4,2,1 我该怎么做。提前致谢。

4

1 回答 1

0

如果你想要所有的祖先和兄弟姐妹,那么在子句中5使用 parent id :start with

/* sample data
with t(id, pid) as (
    select 1, null from dual union all
    select 2,    1 from dual union all
    select 3,    1 from dual union all
    select 4,    2 from dual union all
    select 5,    2 from dual union all
    select 6,    3 from dual ) */ 
select distinct id
  from t connect by prior pid = id
  start with pid = (select pid from t where id = 5)
于 2018-02-07T11:52:50.020 回答