Neo4j Cypher 匹配 AND 与 OR
Neo4j Cypher Match AND vs OR
我有以下 Cypher 查询:
MATCH (childD:Decision)
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false}) WHERE mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0 WITH childD
MATCH (childD)-[mandatoryCriteriaVote5:HAS_VOTE_ON]->(mandatoryCriteriaId5:Criterion {deleted: false}) WHERE mandatoryCriteriaId5.id = 5 AND mandatoryCriteriaVote5.avgVotesWeight >= 3.0 WITH childD
RETURN childD
现在查询的以下部分:
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false}) WHERE mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0 WITH childD
MATCH (childD)-[mandatoryCriteriaVote5:HAS_VOTE_ON]->(mandatoryCriteriaId5:Criterion {deleted: false}) WHERE mandatoryCriteriaId5.id = 5 AND mandatoryCriteriaVote5.avgVotesWeight >= 3.0 WITH childD
作为逻辑运算 AND
。这意味着 childD
必须满足这两个条件才能 return 编辑到查询结果。
如何重写此查询以使其符合逻辑 OR
?
我的意思是 - return 所有 chilD
满足以下任一条件:
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false}) WHERE mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0 WITH childD
或
MATCH (childD)-[mandatoryCriteriaVote5:HAS_VOTE_ON]->(mandatoryCriteriaId5:Criterion {deleted: false}) WHERE mandatoryCriteriaId5.id = 5 AND mandatoryCriteriaVote5.avgVotesWeight >= 3.0 WITH childD
您可以通过如下更新得到相同的结果:
MATCH (childD:Decision)
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false})
WHERE (mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0)
OR (mandatoryCriteriaId1.id = 5 AND mandatoryCriteriaVote1.avgVotesWeight >= 3.0)
RETURN childD
我有以下 Cypher 查询:
MATCH (childD:Decision)
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false}) WHERE mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0 WITH childD
MATCH (childD)-[mandatoryCriteriaVote5:HAS_VOTE_ON]->(mandatoryCriteriaId5:Criterion {deleted: false}) WHERE mandatoryCriteriaId5.id = 5 AND mandatoryCriteriaVote5.avgVotesWeight >= 3.0 WITH childD
RETURN childD
现在查询的以下部分:
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false}) WHERE mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0 WITH childD
MATCH (childD)-[mandatoryCriteriaVote5:HAS_VOTE_ON]->(mandatoryCriteriaId5:Criterion {deleted: false}) WHERE mandatoryCriteriaId5.id = 5 AND mandatoryCriteriaVote5.avgVotesWeight >= 3.0 WITH childD
作为逻辑运算 AND
。这意味着 childD
必须满足这两个条件才能 return 编辑到查询结果。
如何重写此查询以使其符合逻辑 OR
?
我的意思是 - return 所有 chilD
满足以下任一条件:
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false}) WHERE mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0 WITH childD
或
MATCH (childD)-[mandatoryCriteriaVote5:HAS_VOTE_ON]->(mandatoryCriteriaId5:Criterion {deleted: false}) WHERE mandatoryCriteriaId5.id = 5 AND mandatoryCriteriaVote5.avgVotesWeight >= 3.0 WITH childD
您可以通过如下更新得到相同的结果:
MATCH (childD:Decision)
MATCH (childD)-[mandatoryCriteriaVote1:HAS_VOTE_ON]->(mandatoryCriteriaId1:Criterion {deleted: false})
WHERE (mandatoryCriteriaId1.id = 1 AND mandatoryCriteriaVote1.avgVotesWeight >= 1.0)
OR (mandatoryCriteriaId1.id = 5 AND mandatoryCriteriaVote1.avgVotesWeight >= 3.0)
RETURN childD