Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypher: Neighbours of which all neighbours satisfy an inequality

Tags:

cypher

Let's say you have a database that satisfies the following scheme:

(person {name:string, budget:int})
(person)-[:FRIEND]-(person)

How would one query the following in Cypher?

"Give all friends of Alice of whom holds that ALL their friends have a budget that is greater than 100."

like image 508
Pim van Leeuwen Avatar asked Oct 24 '25 16:10

Pim van Leeuwen


1 Answers

You can use the following query in Cypher for this:

MATCH (alice {name:"Alice"})
MATCH (alice)-[:FRIEND]-(f)
MATCH (f)-[:FRIEND]-(person)
WITH f, collect(person) as friends
WHERE ALL(x in friends WHERE x.budget > 100 )
RETURN f, friends
like image 90
Pim van Leeuwen Avatar answered Oct 27 '25 01:10

Pim van Leeuwen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!