【问题标题】:Neo4j Cypher Match AND vs ORNeo4j 密码匹配 AND 与 OR
【发布时间】:2021-12-04 12:24:43
【问题描述】:

我有以下 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 必须同时满足这两个条件才能返回查询结果。

如何重写此查询以便像逻辑 OR 一样工作?

我的意思是 - 返回所有满足以下任一条件的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 

【问题讨论】:

    标签: neo4j cypher


    【解决方案1】:

    您可以通过如下更新获得相同的结果:

    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多