neo4j - 如何知道节点 x 是否具有节点 z 的每个实例,其中它与另一个节点 y 有很多关系,而另一个节点 y 与另一个节点 z 有一个关系?
问题描述
所以我有一个节点:Customer
,它有很多 node :Order
,并且与node:Order
有 1 个关系,这里:Shipper
调用:SHIP_VIA
的是层次结构:
(customer:Customer)-[:PURCHASED]->(order)-[:SHIP_VIA]->(shipper:Shipper)
现在只有 3 个托运人,订单指向他们,一个客户会有很多订单。所以我的问题是如何获得与所有托运人一起发货的所有客户?请注意,每个托运人shipperID
内部都有一个属性。这是我的代码,但除了一个“存在的地方”之外它不起作用
match (customer:Customer)-[:PURCHASED]->(order)-[:SHIP_VIA]->(shipper:Shipper)
WHERE exists((customer)-[:PURCHASED]->(order)-[:SHIP_VIA]->(:Shipper
{shipperID:1})) and exists((customer)-[:PURCHASED]->(order)-[:SHIP_VIA]->
(:Shipper {shipperID:2})) and exists((customer)-[:PURCHASED]->(order)-
[:SHIP_VIA]->(:Shipper {shipperID:3})) return customer, order , shipper;
解决方案
使用collect()和all()函数尝试此解决方案:
// match all shippers
match (shipper:Shipper)
// create a list containing all shippers and pass to the next context
with collect(shipper) as shippers
// match all customers which has purchased an order with each shipper
match (customer:Customer)
where all (shipper in shippers where (customer)-[:PURCHASED]->(:Order)-[:SHIP_VIA]->(shipper))
// return customers
return customer
推荐阅读
- angular - 标签显示为 SyntaxError (1:1) Unknown word
- php - 覆盖php超全局数组可以吗?
- ios - 从孙子视图控制器进行操作 - Swift Xcode
- spring - 使用 Spring Security 进行 Steam 身份验证?
- powershell - 无法使用 powershell 获取打印机列表
- javascript - 尝试使用提供的 localeSubpaths 配置访问任何页面时出现 next-i18next 404 错误
- javascript - 多个:vue中的值
- python-3.x - IndexError:索引超出范围 - word2vec
- c++ - 是否可以制作一个宏来反映 C++ 函数声明?如何?
- spring - Spring Batch Writer 写 Map
归档