Neo4j - NOT IN query

橙三吉。 提交于 2019-12-07 06:07:19

问题


The graph schema I have is (actors)-[:ACTED_IN]->(movies).

I know how to find actors who have worked with a particular actor as below:

MATCH (actor {name:"Tom Hanks"} )-[:ACTED_IN]->(movies)<-[:ACTED_IN]-(costars) return distinct costars;

I know how to find all the actors who have worked in some movie: MATCH (all_actor)-[:ACTED_IN]->(movies) return distinct all_actor;

However I don't know how to find all actors not in costars. How do I go about it?


回答1:


As you want to deduct the coactors from the global list of actors this is not the best graph query, here are some suggestions.

// Max de Marzi
MATCH (actor:Actor {name:"Tom Hanks"})-[:ACTED_IN]->(movie), (other:Actor)
WHERE NOT (movie)<-[:ACTED_IN]-(other)
RETURN other

// Wes Freeman
MATCH (actor:Actor {name:"Tom Hanks"}), (other:Actor)
WHERE NOT (actor)-[:ACTED_IN]->()<-[:ACTED_IN]-(other)
RETURN other


// Michael Hunger
MATCH (actor:Actor {name:"Tom Hanks"} )-[:ACTED_IN]->(movies)<-[:ACTED_IN]-(coactor)
WITH collect(distinct coactor) as coactors
MATCH (actor:Actor)
WHERE NOT actor IN coactors
RETURN actor


来源:https://stackoverflow.com/questions/21185463/neo4j-not-in-query

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!