如何计算人际关系成本

问题描述 投票:0回答:1

我想以最低的成本从一个结到一个结,但我只得到一个关系列表

MATCH (g:city {名称:"格拉茨"})-[c:bus*]->(b:city {名称:"布雷根茨"}) 返回 c.fahrzeit

这个声明给了我一个: 类型不匹配:预期为 Map、Node、Relationship、Point、Duration、Date、Time、LocalTime、LocalDateTime 或 DateTime,但为 List(第 2 行第 8 列(偏移量:72)) “返回 c.fahrzeit”

但声明: MATCH (g:city {名称:"格拉茨"})-[c:bus*]->(b:city {名称:"布雷根茨"}) 返回c

有效并且只给我列表。最终,我想要最短的旅程时间(fahrzeit)

neo4j
1个回答
0
投票

您需要对列表

farzeit
中每个关系的
c
属性的值求和。这可以通过
reduce
函数来完成:

MATCH (g:city { name: "Graz" })-[c:bus*]->(b:city { name: "Bregenz" })
RETURN reduce(acc = 0, rel IN c | acc + rel.fahrzeit) AS gesamt
© www.soinside.com 2019 - 2024. All rights reserved.