图最短路径..只使用标记边?
Graph shortest path .. use only labelled edges?
在新的 SQL 服务器版本中,有功能 SHORTEST_PATH
。
我在边缘表中使用属性(或标签)来区分不同类型的连接。
不幸的是,SHORTEST_PATH
函数似乎不允许 where 条件中的任何属性(如果表被标记为路径)
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
有没有什么技巧可以做到这一点?
看起来您可以在 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'
在新的 SQL 服务器版本中,有功能 SHORTEST_PATH
。
我在边缘表中使用属性(或标签)来区分不同类型的连接。
不幸的是,SHORTEST_PATH
函数似乎不允许 where 条件中的任何属性(如果表被标记为路径)
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
有没有什么技巧可以做到这一点?
看起来您可以在 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'