我需要根据级别将数据拆分为3个不同的列。在下表中,SU_DC_1是基于我需要添加级别的SETTLEUNIT列的顶级。
父母:TOPSETTLUNIT 孩子:SETTLEUNIT
基于Child我需要创建3个额外的列
我发现很难为它编写查询。能帮忙吗?
答案 0 :(得分:3)
类似的东西:
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;