I am trying to create a count table of products based on sales status. Sale status has two value - WON and LOST.
MATCH (sid:Sale)-[:have_outcome]->(ss:SaleStatus {name:'WON'})
MATCH (sid:Sale)-[:sales_of]->(p:Product)
WITH p.name as product, count(sid) as positive
MATCH (sid2:Sale)-[:have_outcome]->(ss2:SaleStatus {name:'LOST'})
MATCH (sid2:Sale)-[:sales_of]->(p2:Product)
RETURN product, positive, count(sid2) as negative
In the output I am not getting right value for 'negative' column
MATCH (p:Product) <-[:sales_of]- (sid:Sale)-[:have_outcome]->(ss:SaleStatus )
With p.name as product, ss.name as type, count(ss) as type_val
With product, collect([type,type_val]) as keypairlist
With product, apoc.map.fromPairs(keypairlist)as value
Return product, COALESCE(value.Won,0) as Won, COALESCE(value.Lost,0) as Lost
I run the query you suggested, unfortunately its showing a error. I tried my part but cant find a solution i am adding error message below. Please suggest a solution if possible.
Unknown function 'apoc.map.fromPairs' (line 4, column 15 (offset: 210))
"With product, apoc.map.fromPairs(keypairlist) as value"
I installed the APOC plugin now its working perfectly.
You provided a perfect code, even replaces the null value.
Thank you so much for your effort and help.