The following nodes relationships
(u:user{id:'some_id'})-[hpl:HAS_PRODUCT_LIST]->(pl:productList)<-[ipl:IN_PRODUCT_LIST]-(p:product)
I need to get the average products per product list.
I tried
MATCH (u:user{id: 'some_id'})-[hpl: HAS_PRODUCT_LIST]->(pl:productList)<-[ipl:IN_PRODUCT_LIST]-(p:product)
WITH count(hpl) as hplc, count(p) as pc
RETURN pc / hplc
I'm getting a wrong calculation.
Let's say there are three product lists plA, plB and plC. Then for plA, you have 2 products, plB has 3 products and plC has 1. Your query will give you 3 / ( 2 + 3 + 1 ) = 3 / 6 = 0.5 which is not correct. The average product count is 6/3 or 2.
Thus, your query should do the count on the product list pl and NOT on the relationship type hpl