我正在使用Neo4j安装附带的示例电影图。
我想得到一个演员(通过名字),他在电影和所有其他电影(他还没有连接)中扮演的角色。
我能得到的最接近的是以下内容,但是演员,角色和actedInMovies重复的次数与其他电影一样多。
MATCH (actor{name:'Bill Paxton'})-[roles:ACTED_IN]->(actedInMovies), (otherMovies:Movie)
WHERE NOT (actor)-[:ACTED_IN]->(otherMovies)
RETURN actor, roles, actedInMovies, otherMovies
如何只为演员,相应电影的角色和所有其他电影获得一个结果?
提前致谢!
答案 0 :(得分:1)
稍微不同的方法如何首先获得Bill Paxton所做的所有电影,然后使用该系列电影找到所有不在其中的电影。然后返回比尔帕克斯顿,他演出的电影集和他没有参演的电影集(即其余部分)
MATCH (actor:Person {name:'Bill Paxton'})-[r:ACTED_IN]->(acted:Movie)
with actor, collect(acted) as acted_in_movies, collect(r) as roles
MATCH (other:Movie)
WHERE none (acted in acted_in_movies where acted = other)
RETURN actor.name, acted_in_movies, roles, collect(other) as other_movies
更新了查询以反映我测试过的数据集。添加了角色名称集合,并将影片节点更改为结果集的标题。
MATCH (actor {name:'Bill Paxton'})-[r:ACTS_IN]->(acted)
with actor, collect(acted) as acted_in_movies, collect(acted.title) as acted_titles, collect(r.name) as roles
MATCH (other:Movie)
WHERE none (acted in acted_in_movies where acted = other)
RETURN actor.name, acted_titles, roles, collect(other.title) as other_movies