--■■■case式を使う方法■■■
select ID,PrevID,
case when exists(select 1 from CloneIsLeaf b
where a.ID = b.PrevID) then 0 else 1 end as isLeaf
from CloneIsLeaf a
Start With ID = 1
connect by prior ID = PrevID;
--■■■order siblings byでソートしない方法■■■
select ID,PrevID,
case when Level < Lead(Level) over(order by RowNum)
then 0 else 1 end as isLeaf
from CloneIsLeaf
Start With ID = 1
connect by prior ID = PrevID;
--■■■order siblings byでソートする方法1■■■
select ID,PrevID,
case when LV < Lead(LV) over(order by RowNum)
then 0 else 1 end as isLeaf
from (select ID,PrevID,Level as LV
from CloneIsLeaf
Start With ID = 1
connect by prior ID = PrevID
order siblings by ID);
--■■■order siblings byでソートする方法2■■■
select ID,PrevID,
case when LV < Lead(LV) over(order by Row_Num)
then 0 else 1 end as isLeaf
from (select ID,PrevID,LV,RowNum as Row_Num
from (select ID,PrevID,Level as LV
from CloneIsLeaf
Start With ID = 1
connect by prior ID = PrevID
order siblings by ID));