使用电影图,我有以下问题:movies where Keanu Reeves AND Robin Williams did not act?
要解决此问题,我有以下两个查询:
MATCH (m:Movie)<-[:ACTED_IN]-(p:Person)
WITH m, collect(p) as actors
WHERE NONE (actor in actors WHERE actor.name IN ['Keanu Reeves', 'Robin Williams','Frank Langella'])
RETURN m
或者:
MATCH (m:Movie)
WHERE NONE(n in ['Keanu Reeves', 'Robin Williams','Frank Langella'] WHERE (m)<-[:ACTED_IN]-(:Person {name:n}))
RETURN m
但是,现在我想看的电影最多只能扮演三部电影中的一部。为此,我搜索了谓词函数,但是找不到找到出现次数的方法。
如何获得一定比例的演员没有表演的电影?
答案 0 :(得分:1)
您可以将NONE与SINGLE组合
MATCH (m:Movie)
WHERE NONE(n in ['Keanu Reeves', 'Robin Williams','Frank Langella'] WHERE (m)<-[:ACTED_IN]-(:Person {name:n}))
OR SINGLE(n in ['Keanu Reeves', 'Robin Williams','Frank Langella'] WHERE (m)<-[:ACTED_IN]-(:Person {name:n}))
RETURN m
或者您可以计算图案外观
MATCH (m:Movie)
OPTIONAL MATCH (m)<-[:ACTED_IN]-(p:Person))
WHERE p.name in ['Keanu Reeves', 'Robin Williams','Frank Langella']
WITH m, COUNT(p) as count
WHERE count < 2
RETURN m