1
我有一个图,其中实体Customer
,Product
和关系ORDERED
。以下是使用cypher计算单个查询中两个节点的总数和它们之间的关系数 - neo4j
(Customer)-[:ORDERED]->(Product)
我想计算产品的总数量,在一个单一的暗号查询订单客户和总人数的总数暗号方式它们之间的关系。
下面是我写的
单查询
MATCH
(c:Customer)-[r:ORDERED]->(p:Product),
(p1:Product),
(c1:Customer)
WITH
count(r) as order_count ,
count(DISTINCT c1) as customer_count ,
count(DISTINCT p1) as product_count
RETURN order_count , customer_count , product_count
查询,但它给错误的结果与所有算作是相同的值执行了很长一段时间。
如果我执行各自独立计数,然后给它的结果非常快速和正确
单独的查询
MATCH (c:Customer)-[r:ORDERED]->(p:Product)
WITH count(r) as order_count
RETURN order_count
MATCH (p1:Product)
WITH count(DISTINCT p1) as product_count
RETURN product_count
MATCH (c1:Customer)
WITH count(DISTINCT c1) as customer_count
RETURN customer_count
谁能解释什么是在单个查询回事?