Use properties of relationship in Cypher query

Hello.

I'm doing a neo4j project.

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

It worked, but can you explain me what i've done wrong please?

What was your reasoning for the duplicated (second) MATCH statement you put in your query, or was it just a copy error?

Ohh, my bad, i just saw it now