繁体   English   中英

NEO4J - 查找节点的所有传入和传出边缘

[英]NEO4J - find all incoming and outgoing edges from a node

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

我试过这样做:

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

我认为你需要分别匹配进出(在这里窃取Christophe的答案):

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM