Oracle
 sql >> Base de données >  >> RDS >> Oracle

Diviser le tableau en colonnes de différents niveaux

Quelque chose comme :

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;