【问题标题】:Cypher query for actors who have not worked with Gene Hackman but have worked with a Director of a Gene Hackman movie未与 Gene Hackman 合作但曾与 Gene Hackman 电影导演合作的演员的 Cypher 查询
【发布时间】:2021-12-30 03:27:19
【问题描述】:

在我目前正在做的 Person,Movie 的 Neo4j 样本数据集中查找 Gene Hackman 电影的导演:

MATCH
  (p1:Person{name:"Gene Hackman"})-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(p2:Person)
RETURN p1, m, p2

我如何找到由 Gene Hackman 电影的导演执导但没有在电影中与 Gene Hackman 一起表演的演员?


这里是一些示例 json 数据,或者更简单的是在 https://sandbox.neo4j.com/ 处选择“电影”数据集

[
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 97,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "It's a hell of a thing, killing a man",
"title": "Unforgiven",
"released": 1992
      }
    },
    "p2": {
"identity": 99,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Clint Eastwood"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 97,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "It's a hell of a thing, killing a man",
"title": "Unforgiven",
"released": 1992
      }
    },
    "p2": {
"identity": 99,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Clint Eastwood"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 97,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "It's a hell of a thing, killing a man",
"title": "Unforgiven",
"released": 1992
      }
    },
    "p2": {
"identity": 98,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Richard Harris"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 97,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "It's a hell of a thing, killing a man",
"title": "Unforgiven",
"released": 1992
      }
    },
    "p2": {
"identity": 169,
"labels": [
        "Person"
      ],
"properties": {
"name": "Jessica Thompson"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 95,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Come as you are",
"title": "The Birdcage",
"released": 1996
      }
    },
    "p2": {
"identity": 60,
"labels": [
        "Person"
      ],
"properties": {
"born": 1951,
"name": "Robin Williams"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 95,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Come as you are",
"title": "The Birdcage",
"released": 1996
      }
    },
    "p2": {
"identity": 96,
"labels": [
        "Person"
      ],
"properties": {
"born": 1931,
"name": "Mike Nichols"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 95,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Come as you are",
"title": "The Birdcage",
"released": 1996
      }
    },
    "p2": {
"identity": 80,
"labels": [
        "Person"
      ],
"properties": {
"born": 1956,
"name": "Nathan Lane"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 95,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Come as you are",
"title": "The Birdcage",
"released": 1996
      }
    },
    "p2": {
"identity": 169,
"labels": [
        "Person"
      ],
"properties": {
"name": "Jessica Thompson"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 88,
"labels": [
        "Person"
      ],
"properties": {
"born": 1970,
"name": "Brooke Langton"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 170,
"labels": [
        "Person"
      ],
"properties": {
"name": "James Thompson"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 168,
"labels": [
        "Person"
      ],
"properties": {
"name": "Angela Scope"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 169,
"labels": [
        "Person"
      ],
"properties": {
"name": "Jessica Thompson"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 1,
"labels": [
        "Person"
      ],
"properties": {
"born": 1964,
"name": "Keanu Reeves"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 91,
"labels": [
        "Person"
      ],
"properties": {
"born": 1950,
"name": "Howard Deutch"
      }
    }
  },
  {
    "p1": {
"identity": 89,
"labels": [
        "Person"
      ],
"properties": {
"born": 1930,
"name": "Gene Hackman"
      }
    },
    "m": {
"identity": 87,
"labels": [
        "Movie"
      ],
"properties": {
"tagline": "Pain heals, Chicks dig scars... Glory lasts forever",
"title": "The Replacements",
"released": 2000
      }
    },
    "p2": {
"identity": 90,
"labels": [
        "Person"
      ],
"properties": {
"born": 1968,
"name": "Orlando Jones"
      }
    }
  }
]

【问题讨论】:

    标签: neo4j cypher graph-databases


    【解决方案1】:

    这应该可行。下次如果可以的话,请附上一个小样本数据集。

    MATCH (p1:Person {name:"Gene Hackman"})-[:ACTED_IN]->(m:Movie)<-[:DIRECTED]-(director:Person)-[:DIRECTED]->(m2:Movie) 
    WHERE NOT (m2)<-[:ACTED_IN]-(:Person {name: "Gene Hackman"}) 
    MATCH (m2)<-[:ACTED_IN]-(p4:Person) 
    RETURN p4
    

    【讨论】:

    • 谢谢 - 对于这些问题,在 Neo4j 中附加示例数据的最佳方法是什么?
    • 用于添加数据的示例密码查询非常适合快速获得帮助。
    • 查询不起作用。让我添加一些示例数据。
    • @David542 该查询有一个单字符拼写错误,所以不允许我编辑(因为它必须是 6 个字符)。引用 m2 应该是节点标签 Movie,而不是 movie。
    • @richard -- 可能会添加评论或缩进,或者做一些不难解决的事情!
    猜你喜欢
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-24
    • 1970-01-01
    相关资源
    最近更新 更多