Database 如何在一条语句中减去Neo4j中具有不同条件的相同返回值

Database 如何在一条语句中减去Neo4j中具有不同条件的相同返回值,database,neo4j,cypher,graph-databases,Database,Neo4j,Cypher,Graph Databases,我正在使用Java来匹配这样的语句。 Result firstResult = db.execute("MATCH (n)-[:someRelation]->(m) WHERE n.name='firstN' RETURN m.cal"); Result secondResult = db.execute("MATCH (n)-[:someRelation]->(m) WHERE n.name='Second' RETURN m.cal"); 那么如何在一次匹配中减去这两条语句,而

我正在使用Java来匹配这样的语句。

Result firstResult = db.execute("MATCH (n)-[:someRelation]->(m) WHERE n.name='firstN' RETURN m.cal");
Result secondResult = db.execute("MATCH (n)-[:someRelation]->(m) WHERE n.name='Second' RETURN m.cal");

那么如何在一次匹配中减去这两条语句,而不需要创建另一个结果(secondResult)?

如果将每一条语句放入一个集合中,然后过滤掉一个集合中不在另一个集合中的语句,您将有效地从另一个集合中减去一条语句

// put the result of the first set in a collection
MATCH (n)-[:someRelation]->(m) 
WHERE n.name='firstN' 
WITH collect(m.cal) as m_cal_coll_1
//
// put the second set in a collection
MATCH (n)-[:someRelation]->(m) 
WHERE n.name='Second'
WITH m_cal_coll_1, collect(m.cal) as m_cal_coll_2
//
// return items in the first that are not in the second
return filter(x IN m_cal_coll_1 WHERE not x in m_cal_coll_2 )