简体   繁体   中英

CYPHER, NEO4J Returning couples of nodes that are connected by a relationship of type A and not by a relation of type B

I am working on the Neo4j tutorial Movies database. I would like to make a query that returns the people that directed a movie but did not produced it.

In order to accomplish this I have used the query:

match (m:Movie)<-[:DIRECTED]-(p:Person)-[r]->(m) where type(r) <> 'PRODUCED' return p 

Nevertheless, if I make it return * I still get these couples (person, movie) where the person not only directed and produced the film but also wrote it:

In the image there is one of the not admissible couples that are returned by my query

On the contrary, the query seems to successfully rule out all those couples that are with only the two relationships 'PRODUCED' and 'DIRECTED'.

Is there a way of writing this query so that I can rule out all these couples as well?

You can use path pattern in WHERE :

match (m:Movie)<-[r:DIRECTED]-(p:Person) 
where not (p)-[:PRODUCED]->(m)
return m, p, r

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM