Mathematical Operation in Result

27 views
Skip to first unread message

Pablo Ramirez

unread,
Oct 24, 2012, 1:10:08 AM10/24/12
to ne...@googlegroups.com
I'm using neo4j 1.9 SNAPSHOT and I need to do a query in which consist order the result, here no problem,
but I need to divide the first element by the second element, any idea?
Is this possible in the query or using a Map Iterator?

Wes Freeman

unread,
Oct 24, 2012, 1:27:44 AM10/24/12
to ne...@googlegroups.com
It would be nice to see your original query/output. So, I'm assuming you will always only have two results? I'm not quite sure I understand, but here goes...

You can do something like this (the age value is a stupid example here, but I had some age data already in console):
start n=node(*) 
where has(n.age) 
// first, let's get our order right before we call collect
with n 
order by n.age  
// probably not necessary if you know you have two results
limit 2
// let's merge this into a collection so we can get a single result
with collect(n.age) as coll 
// and then do the math with the head/tail of the list
return head(coll)/head(tail(coll));


--
 
 

Pablo Ramirez

unread,
Oct 24, 2012, 11:58:09 PM10/24/12
to ne...@googlegroups.com
Thanks Wes, that could be very useful, I'll try it.
The query is this:
"Get all childs connected to a X node and order DESC. Divide firstNode/secondNode..."

At the moment I only have the query to get all the childs connected to X node:
START n=node(200) MATCH n<-->nodo RETURN nodo.ind, nodo.lev, nodo.id, nodo.mass, nodo.x, nodo.y, nodo.z ORDER BY nodo.mass DESC
Reply all
Reply to author
Forward
0 new messages