with test as (
select 'A' as bfr,'B' as aft from dual
union all
select 'B' as bfr,'C' as aft from dual
union all
select 'C' as bfr,'D' as aft from dual
union all
select 'D' as bfr,'E' as aft from dual
union all
select 'F' as bfr,'G' as aft from dual
union all
select 'G' as bfr,'H' as aft from dual
)
테이블 test
==========
bfr aft
==========
A B
B C
C D
D E
F G
G H
I J
=========
전행 aft와 후행 bfr을 연결하여 마지막 aft을 찾습니다. 그러고서 bfr을 마지막 aft로 매핑시키고자 합니다.
얻고자 하는 결과는
============
A E
B E
C E
D E
F H
G H
I J
============
어떻게 SQL를 작성하면 위와 같은 나올까요?
도와주세요.
감사합니다.
|