【发布时间】:2016-01-25 00:52:49
【问题描述】:
我的图表中有地点和人物作为标签,以及关系“knows_the_place”。喜欢:
(person)-[knows_the_place]->(place)
一个人通常知道多个地方。
现在我想通过地点(有很多共同的“地点”)找到具有“强”关系的人,例如,我想查询共享至少 3 个不同地点的所有人,像这样(不工作!)查询:
MATCH
(a:person)-[:knows_the_place]->(x:place)<-[:knows_the_place]-(b:person),
(a:person)-[:knows_the_place]->(y:place)<-[:knows_the_place]-(b:person),
(a:person)-[:knows_the_place]->(z:place)<-[:knows_the_place]-(b:person)
WHERE NOT x=y and y=z
RETURN a, b
如何使用 neo4j Query 做到这一点?
额外问题:
与其向我展示与另一个人有 x 个地方相同的人,更好的是,如果我能获得如下订单列表:
a 与 b 共享 7 个位置 c 与 b 共享 5 个位置 d 与 e 共享 2 个位置 f 与 a 共享 1 个位置 ...
感谢您的帮助!
【问题讨论】:
-
neo4j select nodes that have at least n relations 可能重复 count 关键字是关键 ;)
-
另外,小吹牛:Neo4j 风格一般是有标签的 CamelCase。这是一个指南:nigelsmall.com/zen