The*_*ode 4 database neo4j graph-databases cypher
我正在使用 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");
Run Code Online (Sandbox Code Playgroud)
那么如何在一次匹配中减去这两个语句而无需创建另一个 Result (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 )
Run Code Online (Sandbox Code Playgroud)