如何知道Node x是否包含节点z的每个实例,它与另一个与另一个节点z有一个关系的节点y有很多关系?

时间:2018-05-10 05:29:49

标签: neo4j cypher

所以我有一个节点:Customer,其中包含许多节点:Order,而:Order:Shipper节点:SHIP_VIA的关系必须为1 {}} :

(customer:Customer)-[:PURCHASED]->(order)-[:SHIP_VIA]->(shipper:Shipper)

现在只有3个托运人,订单指向他们,而客户会有很多订单。所以我的问题是如何让所有托运人都附带所有客户?请注意,每个托运人都有一个shipperID属性。这是我的代码,但它没有工作,除了一个" where exists"

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;

2 个答案:

答案 0 :(得分:0)

使用collect()all()函数尝试此解决方案:

freq='20d'

答案 1 :(得分:0)

  1. 计算托运人总数
  2. 对于每位客户,请确认唯一托运人的数量等于托运人总数
  3. MATCH (shipper:Shipper) 
    WITH count(shipper) AS totalShippers
    
    MATCH (customer:Customer)-[:PURCHASED]->(order)-[:SHIP_VIA]->(shipper:Shipper)
    WITH totalShippers, customer, 
         COUNT(DISTINCT shipper) as shippers WHERE totalShippers = shippers
    
    RETURN customer