[英]Graph shortest path .. use only labelled edges?
With the new SQL Server version there is the function SHORTEST_PATH
.随着新的 SQL 服务器版本有 function
SHORTEST_PATH
。 I use attributes (or Labels) in the edge tables to distinguish the different types of connections.我使用边缘表中的属性(或标签)来区分不同类型的连接。
Unfortunately the SHORTEST_PATH
function doesn't seem to allow any attributes in the where condition (if the tables are marked for path)不幸的是,
SHORTEST_PATH
function 似乎不允许 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
Is there a no trick to how to do that anyway?无论如何,如何做到这一点没有诀窍吗?
Looks like you can use a subquery in the from
clause.看起来您可以在
from
子句中使用子查询。 eg例如
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'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.