【发布时间】:2014-10-09 10:59:46
【问题描述】:
我有一个包含实体Customer、Product 和关系ORDERED 的图表。以下是它们在 Cypher 方式中的关系
(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
谁能解释一下单个查询中发生了什么?
【问题讨论】:
标签: neo4j cypher graph-databases