ADDITIONAL MATCH and WHERE in Cypher

I am trying to write cypher-query.

Graph

The full chart is shown below. Some films do not have a stuntman (fictional schedule).

Question

I want to get ALL ACTORS (AND THEIR MOVIES) who have never played a movie with a stuntman. In this case, it will be "Johnny Depp"

Full cipher count

+4
source share
2 answers

This should work:

MATCH (n:Actor)-->(m:Movie)
WHERE NOT (n)-->()<--(:Stuntman)
RETURN n AS actor, collect(m) AS movies

Greetings

PS: there is another solution, but I find it less productive:

MATCH (n:Actor)-->(m:Movie)
WITH n AS actor, collect(m) AS movies
WHERE all(m IN movies WHERE not (m)<--(:Stuntman))
RETURN actor, movies
+4
source

I think it will make you go

// Find the actors and their movies
MATCH (a:Actor)--(m:Movie)

// where the actor was never in a movie with a stuntman
WHERE NOT (a)-[:ACTS_IN]-(:Movie)-[:ACTS_IN]-(:Stuntman)
RETURN a,m
+2
source

Source: https://habr.com/ru/post/1679458/


All Articles