我想在cypher中写一个查询,以便找出有多少演员在brock lesnar所扮演的所有电影中扮演过角色。我的计划是收集brocklesnar所扮演的所有电影,然后循环播放每部电影,看看所有电影中是否有共同演员。我无法编写相同的查询。谁能给我一些如何解决这个问题的建议?
match (a:`ACTOR` {name: 'Brock Lesnar'})-[:ACTS_IN]->(m:`MOVIES`) collect(m.title) as movies foreach(c in movies return (actor)-[:ACTS_IN]->(c))
这是我到目前为止所写的内容。我知道这不对,但这是我遇到问题的地方
答案 0 :(得分:1)
下面的Cypher查询将使用您的可选架构为您提供Brock Lesnar的有序列表。
MATCH (actor:ACTOR { name: "Brock Lesnar" })-[:ACTS_IN]->(movie:MOVIES)
WITH collect(movie) as movies, actor
MATCH (coactors:ACTOR)-[:ACTS_IN]->()<-[:ACTS_IN]-(actor)
WHERE ALL(movie in movies WHERE (movie)<-[:ACTS_IN]-(coactors))
RETURN DISTINCT coactors.name
答案 1 :(得分:-1)
这是我创建的查询。它首先收集了lesner所扮演的所有电影。然后检查所有演员是否已经在所有电影中演出
MATCH (actor:ACTOR{name:'Brock Lesnar'})-[:ACTS_IN]->(movie)
with actor,collect(movie.title) as movieCollection
WHERE ALL (movies IN movieCollection WHERE (actor)-[:ACTS_IN]->(movies)) AND NOT actor.name = "Brock Lesnar"
return actor.name