Is there any way to find nodes having a property with closest integer values with respect to an argument in Neo4j?

Viewed 38

I need to search nodes having property "totalValue", now i need to find 10 nodes having value closest to 100. I need some help to write a query which can return me required results.

1 Answers

Compute the distance, order by distance, limit to 10 ...

MATCH (n:Node)
RETURN n.totalValue AS value, abs(100 - n.totalValue) AS distance
ORDER BY distance
LIMIT 10;

Hope this helps.

Regards, Tom

Related