using MAX Aggregation function in Cypher

1,306 views
Skip to first unread message

Mahdi Negahi

unread,
Apr 23, 2012, 8:33:00 AM4/23/12
to ne...@googlegroups.com
Dear firends

please see this simple graph database. I want to write a cypher query that extract the oldest john's friend.(means Samanta)

Peter Neubauer

unread,
Apr 23, 2012, 9:33:50 AM4/23/12
to ne...@googlegroups.com
Nega

Normally, a query should look like

start john=node(2) match john-[r:friend]->friend where
r.age=max(r.age) return friend

see http://docs.neo4j.org/chunked/snapshot/query-aggregation.html#aggregation-max
(and the live console button in there)

However, this exhibited a bug, that is going to be fixed soon,
https://github.com/neo4j/community/issues/446 . Keep track of that
one!

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j

Peter Neubauer

unread,
Apr 23, 2012, 9:39:14 AM4/23/12
to ne...@googlegroups.com
Btw,
this is wrong, you need to aggregate first in order to get the max
value and pipe it into a second subquery, so the query would become

start n=node(1) match n-[f:friend]->m with n,max(f.age) as age match
n-[f:friend]->m where f.age = age return m

tracked in the same issue.

Cheers,

/peter neubauer

G:  neubauer.peter
S:  peter.neubauer
P:  +46 704 106975
L:   http://www.linkedin.com/in/neubauer
T:   @peterneubauer

If you can write, you can code - @coderdojomalmo
If you can sketch, you can use a graph database - @neo4j

Mahdi Negahi

unread,
Apr 23, 2012, 10:31:26 AM4/23/12
to ne...@googlegroups.com
thanks

Michael Hunger

unread,
Apr 24, 2012, 12:43:31 PM4/24/12
to ne...@googlegroups.com
As you can see on the issue, it is fixed in 1.8-SNAPSHOT.

https://github.com/neo4j/community/issues/446

You can try it live with the neo4j-console: http://tinyurl.com/6tk7fdx

Thanks to Andrés for taking care of it.

Cheers

Michael

Reply all
Reply to author
Forward
0 new messages