Oracle
 sql >> Database >  >> RDS >> Oracle

Dividi la tabella in colonne di diversi livelli

Qualcosa come:

SELECT topsettlunit,
       settleunit,
       CONNECT_BY_ROOT( topsettlunit ) AS level1,
       CASE LEVEL
         WHEN 1 THEN settleunit
         WHEN 2 THEN topsettlunit
       END AS level2,
       CASE LEVEL
         WHEN 2 THEN settleunit
       END AS level3
FROM   your_table
START WITH topsettlunit NOT IN ( SELECT settleunit FROM your_table )
CONNECT BY PRIOR settleunit = topsettlunit;