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

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

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

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

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

von4xj4u

von4xj4u1#

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

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

相关问题