gpt4 book ai didi

graph - NEO4J - 从一个节点找到所有传入和传出的边

转载 作者:行者123 更新时间:2023-12-01 03:36:55 25 4
gpt4 key购买 nike

我想找到所有传出边的数量与同一节点的所有传入边的数量之间的差异。节点是城市,关系是它们之间的转移。

我试过这样做:

MATCH ()-[i:TRANSFERS]->(n:City {name:"London"}),(n:City {name:"London"})-[o:TRANSFERS]->() 
RETURN distinct n.name, count(i) AS incoming, count(o) as outgoing, count(o)-count(i) AS difference
ORDER BY outgoing - incoming DESC

和这个:
MATCH ()-[i:TRANSFERS]->(n:City {name:"London"})
OPTIONAL MATCH (n:City {name:"London"})-[o:TRANSFERS]->()
RETURN distinct n.name, count(i) AS incoming, count(o) as outgoing, count(o)-count(i) AS difference
ORDER BY outgoing - incoming DESC

但它们似乎不起作用。任何的想法?

最佳答案

您可以在传入和传出连接的关系模式上使用大小:

MATCH (city:City {name:"London"})
WITH size((city)-[:TRANSFERS]->()) as out,
size((city)<-[:TRANSFERS]-()) as in,
city
RETURN city, in, out, (out - in) as diff
ORDER BY diff DESC

关于graph - NEO4J - 从一个节点找到所有传入和传出的边,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33867043/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com