Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/three.js/2.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 server 带有'的祖先路径;路径id';或';组“U id”;和';级别';在SQL Server 2008中_Sql Server_Recursion_Grouping - Fatal编程技术网

Sql server 带有'的祖先路径;路径id';或';组“U id”;和';级别';在SQL Server 2008中

Sql server 带有'的祖先路径;路径id';或';组“U id”;和';级别';在SQL Server 2008中,sql-server,recursion,grouping,Sql Server,Recursion,Grouping,我有下表: pairID source_issue_id destination_issue_id ---------------------------------------------- 1 J I 2 B C 3 J M 4 F I 5 A B

我有下表:

pairID  source_issue_id   destination_issue_id
----------------------------------------------
1          J                I
2          B                C
3          J                M
4          F                I
5          A                B
6          A                E
7          N                O
8          J                L
9          C                D
10         P                Q
11         G                H
12         B                F
13         L                K
14         C                N
15         A                G
16         E                F
表示图中的节点

我没有使用
pairID
,因为它似乎没有什么用处

我想获得所有节点的祖先路径、每对节点出现的级别、完整路径和“路径组”

到目前为止,我使用了以下代码:

;with auxPairs as 
(
    select 
        1 as lvl, 
        b.source_issue_id, 
        b.destination_issue_id, 
        cast((b.source_issue_id+ '|' + b.destination_issue_id) as varchar(50)) as "full_path"
    from 
        Pairs2 b
    where
        b.source_issue_id not in (select destination_issue_id from Pairs2)

    union all

    select 
        lvl+1 as lvl, 
        c.source_issue_id, 
        c.destination_issue_id,
        CAST((a.full_path + '|' + c.destination_issue_id) as varchar(50)) as "full_path" 
    from 
        Pairs2 c
    join 
        auxPairs a on a.destination_issue_id = c.source_issue_id
)
返回
lvl
中两个节点(例如A | B为级别1)的“连接级别”、源节点和目标节点以及完整路径(直到该对),例如

对于树中的每条路径,依此类推

我需要添加一个
Path\u id
group\u id
以便获得:

path_id   lvl   source   destination   full_path
------------------------------------------------
1         1     A        B             A|B
1         2     B        C             A|B|C
1         3     C        N             A|B|C|N
1         4     N        O             A|B|C|N|O
2         1     A        B             A|B
2         2     B        C             A|B|C
2         3     C        D             A|B|C|D
....
这意味着具有相同路径id的节点按给定顺序连接


注意:字母顺序的“假”顺序将不适用于实际数据。我需要使用
path\u id
lvl
来建立路径内的部分顺序。

我通过一个简单的图形可视化程序运行数据,并且有多条路径指向F节点(B和E都是父节点).您希望该节点的输出是什么?A | E | F | I A | B | F | I因此,我认为我需要从下至上进行分组谢谢!A | E | F | I,A | B | F | I因为这一点,我认为我需要从下至上进行分组谢谢!我通过一个简单的图形可视化程序运行了您的数据,并且有多个pA到F节点(B和E都是父节点)。您希望该节点的输出是什么?A | E | F | I A | B | F | I因为这个,我认为我需要从下到上进行分组谢谢!A | E | F | I,A | B | F | I因为这个,我认为我需要从下到上进行分组谢谢!
path_id   lvl   source   destination   full_path
------------------------------------------------
1         1     A        B             A|B
1         2     B        C             A|B|C
1         3     C        N             A|B|C|N
1         4     N        O             A|B|C|N|O
2         1     A        B             A|B
2         2     B        C             A|B|C
2         3     C        D             A|B|C|D
....