Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何在一个表上查找父子关系的所有子项_Sql_Oracle_Oracle Sqldeveloper - Fatal编程技术网

Sql 如何在一个表上查找父子关系的所有子项

Sql 如何在一个表上查找父子关系的所有子项,sql,oracle,oracle-sqldeveloper,Sql,Oracle,Oracle Sqldeveloper,如何找到文件夹下的所有子项?就像在资源管理器中,你有一个文件夹在neeth下,你有文件夹+文件夹等 我想找到文件夹2下的所有文件夹 我正在使用oracledb Folder 1 | | | Folder 2 | | | | | Folder 3 | | | | | | | Folder 7 | | | | | | | Folder 8 | | | | | Folder 4 | | | Folder 5 | | | Folder 6 | Folder 10 这个查询为我

如何找到文件夹下的所有子项?就像在资源管理器中,你有一个文件夹在neeth下,你有文件夹+文件夹等

我想找到文件夹2下的所有文件夹

我正在使用oracledb

Folder 1
| |
| Folder 2
| |  |
| |  Folder 3
| |  |  |
| |  |  Folder 7
| |  |  |
| |  |  Folder 8
| |  |
| |  Folder 4
| |
| Folder 5
| |
| Folder 6 
|
Folder 10
这个查询为我提供了父层次结构

SELECT AL_ITEM_ID, AL_FATHER_ID, AL_DESCRIPTION
FROM ALL_LISTS
CONNECT BY AL_ITEM_ID = PRIOR AL_FATHER_ID
start with AL_DESCRIPTION = 'Folder 7'

我认为这会奏效:

Select
    al_item_id, 
    al_father_id,
    al_description
From 
    all_lists
Connect By 
    Prior al_item_id = al_father_id
Start With
    al_description = 'Folder 2'
Where
    Level > 1
如果不是,这几乎可以肯定,这取决于where是在connect之前还是之后通过以下方式进行计算:

Select
    al_item_id,
    al_father_id,
    al_description
From (
    Select
        al_item_id, 
        al_father_id,
        al_description,
        level as lvl
    From 
        all_lists
    Connect By 
        Prior al_item_id = al_father_id
    Start With
        al_description = 'Folder 2'
    ) x
Where
    lvl > 1

只需将Previor放在另一边
通过Previor al_item_id=al_father_id连接
,然后
从更高层次的东西开始。好的工作。如果我从文件夹2开始,我将如何不在列表中显示文件夹2?现在我看到文件夹2,3,7,8。如何获取文件夹3、7、8