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
誰能解釋什麼是在單個查詢回事?