I'm trying to use the avg() function in a property of a relationship
This is my query:
MATCH (E1:ENTITY)-[C:CONTRACT]->(E2:ENTITY)
WITH C.price as contractPrice
MATCH (E1:ENTITY)-[C:CONTRACT]->(E2:ENTITY)
WITH collect([E1,E2,contractPrice]) AS costRecords, avg(C.price) AS avgContractPrice
WITH [record IN costRecords WHERE record[2] > avgContractPrice] as costRecords
UNWIND costRecords as record
RETURN record[0] as E1, record[1] as E2, record[2] as cost
So what i'm trying to show is all the "node-relationship-node" graph, where the price(C.price) is greater than the average, but i get the same result as MATCH n RETURN n
What do i have to change?
Thank you all and stay safe
Try this:
MATCH (E1:ENTITY)-[C:CONTRACT]->(E2:ENTITY)
WITH C.price as contractPrice, E1, E2
WITH collect([E1,E2,contractPrice]) AS costRecords, avg(contractPrice) AS avgContractPrice
WITH [record IN costRecords WHERE record[2] > avgContractPrice] as costRecords
UNWIND costRecords as record
RETURN record[0] as E1, record[1] as E2, record[2] as cost