简体   繁体   English

Sql 树结构查询 Fetch

[英]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 个表

  1. ParentTable -Id of parent and description ParentTable - 父和描述的Id
  2. Version Table- Version ID(Vesrion_1, Version_2) and Version Description(Desc for version) and Main Parent it belongs to (Parent_! or Parent_2) and also its immediate parent(For Version Id Version_1_1_1 Immediate Parent will be stored as Version_1_1) and also the level (Version_1_1 is at level3)版本表 - 版本 ID(Vesrion_1,Version_2)和版本描述(版本的描述)和它所属的主要父级(Parent_! 或 Parent_2)以及它的直接父级(对于版本 ID Version_1_1_1 直接父级将被存储为 Version_1_1)以及级别(Version_1_1 在级别 3)
  3. Activity Table- Active version of the versions for all the parents.活动表 - 所有父母版本的活动版本。 - Version ID(Vesrion_1, Version_2) and also its immediate parent(For Version Id Version_1_1_1 Immediate Parent will be stored as Version_1_1) and also the level (Version_1_1 is at level3) - 版本 ID(Vesrion_1, Version_2) 及其直接父级(对于版本 ID Version_1_1_1 直接父级将存储为 Version_1_1)以及级别(Version_1_1 处于级别 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM