MATCH (s:Sales)
WITH s.ProductID as pid, s.CustomerID as cid, sum(s.salesAmount) as sa
CALL {
WITH pid, sum(sa) as saProduct RETURN saProduct
}
CALL {
WITH cid, sum(sa) as saProduct RETURN saCustomer
}
RETURN pid, cid, saProduct, saCustomer, sa
You can also check out apoc.agg.stats
and comment on this issue
and when i use call command in my request, it does'nt get the same result.
but when i use union command, thats work
MATCH (c:customer)-[rel:buy]->(s:sales)<-[rel2:sold]-(p:product)
MATCH (sm:sales_amount {sales_amount_id: s.sales_id})
WITH c.customer_id as cid,p.product_id as pid,sum(sm.sales_amount) as sum
RETURN cid, pid, sum
UNION
MATCH (c:customer)-[rel:buy]->(s:sales)<-[rel2:sold]-(p:product)
MATCH (sm:sales_amount {sales_amount_id: s.sales_id})
WITH null as cid, null as pid, sum(sm.sales_amount) as sum
RETURN cid, pid, sum
UNION
MATCH (c:customer)-[rel:buy]->(s:sales)<-[rel2:sold]-(p:product)
MATCH (sm:sales_amount {sales_amount_id: s.sales_id})
WITH c.customer_id as cid, null as pid, sum(sm.sales_amount) as sum
RETURN cid, pid, sum;
do you have any idea how can i use call and with to replace union im my requeste to optimize it?