图形最短路径只使用带标签的边?

azpvetkf  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(343)

对于新的sql server版本,有以下功能 SHORTEST_PATH . 我使用边表中的属性(或标签)来区分不同类型的连接。
不幸的是 SHORTEST_PATH 函数似乎不允许where条件中的任何属性(如果表被标记为path)

SELECT
       l1.CommonName AS CommonName, 
       STRING_AGG(l2.CommonName, '->') WITHIN GROUP (GRAPH PATH) AS Verbindung,
       LAST_VALUE(l2.CommonName) WITHIN GROUP (GRAPH PATH) AS LastNode
 from           object as l1, 
                connections for path as v,
                object for path as  l2 
    where match(SHORTEST_PATH( l1  (-(v)-> l2)+))
    and l1.CommonName = 'jagdtWurst'
    and v.label= 'hierarchie' <<--- This is not possible .... Error

有没有什么诀窍怎么做呢?

von4xj4u

von4xj4u1#

看起来可以在中使用子查询 from 条款。如

SELECT
       l1.CommonName AS CommonName, 
       STRING_AGG(l2.CommonName, '->') WITHIN GROUP (GRAPH PATH) AS Verbindung,
       LAST_VALUE(l2.CommonName) WITHIN GROUP (GRAPH PATH) AS LastNode
 from           object as l1, 
                (select * from connections where label = 'hierarchie') for path as v,
                object for path as  l2 
    where match(SHORTEST_PATH( l1  (-(v)-> l2)+))
    and l1.CommonName = 'jagdtWurst'

相关问题