[英]Graph shortest path .. use only labelled edges?
隨着新的 SQL 服務器版本有 function SHORTEST_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
無論如何,如何做到這一點沒有訣竅嗎?
看起來您可以在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'
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.