[英]Sql Tree structure query Fetch
I want to see my structure is such as below:我想看看我的结构如下:
Parent_1 (Lvl1)
>>Version_1(Lvl2)(first child of Parent_1)
>>> Version_1_1(Lvl3)
>>>> Version_1_1_1(Lvl4)
>>>> Version_1_1_2(Lvl4)
>>>Version_1_2(Lvl3)
>>>Version_1_3(Lvl3)
>>>>Version_1_3_1(Lvl4)
>>>>Version_1_3_2(Lvl4)
>>>>>Version_1_3_2_1(Lvl5)
>>Version_2(Lvl2) (second child of Parent_1)
Parent_2 (Lvl1)
>>Version_3(Lvl2)(only child of Parent 2)
I want my data to be visible like this tree structure.我希望我的数据像这种树结构一样可见。 Sort my Parent level asc , next child of the first parent and further down like a tree.
将我的 Parent level asc 排序,第一个父级的下一个子级,然后像树一样向下排序。
Data is split in 3 tables数据分为 3 个表
How can i achieve the above structure.我怎样才能实现上述结构。 I wil have version upto 5 levels for each parent.
我将为每个父母提供多达 5 个级别的版本。 I want the view to user be in the above structure with all the data i have in format mentioned above
我希望用户的视图采用上述结构,其中包含我采用上述格式的所有数据
Thanks in advance提前致谢
You may want to look at the "connect by prior" in SQL.您可能想查看 SQL 中的“按先前连接”。 Yet I warn you about the performance issue, you might prefer to use a string to rank your results and query it.
但是我警告您有关性能问题,您可能更喜欢使用字符串来对结果进行排名并进行查询。
root : 0000根:0000
L1 : 1000 L1 : 1000
L2 : 2000 L2 : 2000
L1-1 : 1100 ... L1-1 : 1100 ...
then you can order by tree_code and filter with like("11%")然后您可以按 tree_code 排序并使用 like("11%") 过滤
Pour info la syntaxe de mise en œuvre des requêtes hiérarchiques est : Pour info la syntaxe de mise en œuvre des requêtes hiérarchiques est :
SELECT * FROM NOM_TABLE
CONNECT BY [NOCYCLE]
[PRIOR] colonne01 = [PRIOR] colonne02 [AND ...]
[START WITH condition] ;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.