Reputation: 168
Using the movie graph, I have the following question: movies where Keanu Reeves AND Robin Williams did not act?
To solve this I have these two queries:
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
Or:
MATCH (m:Movie)
WHERE NONE(n in ['Keanu Reeves', 'Robin Williams','Frank Langella'] WHERE (m)<-[:ACTED_IN]-(:Person {name:n}))
RETURN m
But now I would like to get movies where at maximum one of the three acted. To do that I searched for the predicate functions but I could not find a way to get the count of appearances.
How could I get movies where a percentage of given actors did not act?
Upvotes: 0
Views: 215
Reputation: 8833
You could combine NONE with 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
Or you could count the pattern appearance
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
Upvotes: 1