cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Query on relationships with Cypher

AjejeBrazorf
Node Link

Hi. I'm learning neo4j and I have to make a simple query, but I'm not able to make it.
Suppose to have the graph below.
I want to return all the nodes connected to the node A
and the maximum of the values on the edges between two consecutive nodes(which is an attribute of the relation). I show an example in the picture below.

I did it for path of length one with this query:

MATCH (p {id:"A"})<-[r:HAS]-(t)
RETURN p,max(r.value),t

But I don't know how to make a query for a path longer than one, just because I can't do

MATCH (p {id:"A"})<-[r:HAS*]-(t)
RETURN p,max(r.value),t

I got this error : Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List
3X_5_3_53182787df68a8c5e83ab84f4141f2fd9c2439b5.jpeg
3X_1_8_18815d41090f4774fe95b10cec2d9cfab9844110.jpeg

1 ACCEPTED SOLUTION

Cobra
Ninja
Ninja

Hello @AjejeBrazorf and welcome to the Neo4j community

Sorry, new syntax, I always forget about it.

MATCH path=(a {id:"A"})<-[:HAS*]-(b)
RETURN a,b, max([r in relationships(path) | r.value])

Regards,
Cobra

View solution in original post

4 REPLIES 4

AjejeBrazorf
Node Link

Hello Cobra.
Thank you for your reply.
It gives me this error
"Can't use aggregate functions inside of aggregate functions. "

AjejeBrazorf
Node Link

Yeah I have APOC. But this leads me to the same error I have reported in the question:
"Type mismatch: expected Map, Node, Relationship, Point, Duration, Date, Time, LocalTime, LocalDateTime or DateTime but was List<Relationship"

Cobra
Ninja
Ninja

Hello @AjejeBrazorf and welcome to the Neo4j community

Sorry, new syntax, I always forget about it.

MATCH path=(a {id:"A"})<-[:HAS*]-(b)
RETURN a,b, max([r in relationships(path) | r.value])

Regards,
Cobra

AjejeBrazorf
Node Link

Thanks a lot. This perfectly works!
Thanks for your time.

Regards
Ajeje