简体   繁体   English

Neo4J:在Cypher中来回连接

[英]Neo4J: Joining back and forth in Cypher

I have the following Nodes in a Neo4J DB (Northwind DB): 我在Neo4J DB(Northwind DB)中具有以下节点:

  • Customer
  • Order
  • Product

The nodes have the following relationship: 节点具有以下关系:
(c:Customer)-->(o:Order)--> (p:Product)

How can I get the Products , and the count of the products, that have been bought by Customers , who also bought a Product with pr_ID =2? 我怎样才能获得的Products ,产品的数量,已经由购买Customers ,谁也买了Productpr_ID = 2?

I have tried the following query. 我尝试了以下查询。 It returns the correct items, but the wrong counts: 它返回正确的项目,但计数错误:

MATCH (p:Product)<--(o:Order)<--(c:Customer) 
WITH p,o,c WHERE p.productID='2' 
MATCH c-->(od:Order)-->(pr:Product) 
WITH c,od,pr WHERE NOT pr.productID='2' 
RETURN pr.productName, count(pr.productName)

you need to filter the product id before passing them with the WITH : 您需要先过滤产品ID,然后再将其传递给WITH:

MATCH (c:Customer)-->(o:Order)-->(p:Product {productId: '2'})
MATCH (c)-->(:Order)-->(p2:Product)
WHERE p2 <> p
RETURN p2.productName, count(*) as c

我的查询不起作用的原因是,我使用了count(pr.productName)而不是count(DISTINCT od)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM