gpt4 book ai didi

neo4j cypher 多节点之间的关系

转载 作者:行者123 更新时间:2023-12-01 10:50:42 24 4
gpt4 key购买 nike

例如:

a-[r]->b, there are multi r between the two nodes, each r.userId is unique.
(eg: a-[r:R {userId:"user1"}]->b, (a-[r:R{userId:"user2"}]->b,
and the same for a-[r]->c

而情况是a-[r]->b有关系:r.userId = amdin,而a-[r]->c没有这种关系。

我怎么只返回c.

我尝试创建密码:

"MATCH (a:SomeLabel)-[r:SomeR]->(any:SomeLabel) "
"WHERE id(a)=0 AND r.userId <> \"admin\" "
"RETURN any";

但这也会返回 b ,因为 a->b 有其他关系:r.userId=xxxx

我如何编写密码以返回不包含 user.Id="admin"的节点......

如果您不清楚我在说什么,请告诉我....我需要您的帮助来解决这个问题..谢谢

我在下面画了一张图,多关系命名为sr但是属性不同(userId是唯一的),我想找到与节点 A 相关但不包含 sr {userId:admin} 的所有节点,我在那里添加了红色下划线。所以如图所示,节点B有关系sr {userId:admin},所以我只想返回节点C,没有节点B

enter image description here

最佳答案

为了显示图形问题的简单表示,graphgists非常有用,因为人们可以探索数据。我根据您的描述创建了一个:http://gist.neo4j.org/?94ef056e41153b116e4f

对于您的问题,您可以收集每对节点的关系中涉及的所有用户名,并根据这些用户名进行过滤:

MATCH (a { name:'A' })-[r:sr]->b
WITH a,b, collect(r.name) AS usernames
WHERE NOT 'admin' IN usernames
RETURN a, b

关于neo4j cypher 多节点之间的关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20779786/

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