Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-28-2021 06:26 AM
I would like to match a path where the end nodes share the same property value. Let me use Neo4J's classic movies dataset to illustrate my question
Suppose I want to find out scenarios where a director has a working relationship with two or more actors that share the same birth year. That is,
(1) the director had directed a movie where there was two or more actors that share the same birth year; or
(2) the director had directed multiple movies, where the different actors in each different movies share the same birth year.
I don't have any fixed particular director, movie or actors in mind. I've attempted the following cypher syntax:
However, my syntax looks very convoluted given that this is a simple query. In addition, I'm limited to just finding two actors with the same birth year with this syntax of mine. I also want to find cases where there are three, four or more actors with the same birth year having a working relationship with the director. Lastly, I'm not even confident whether or not this syntax of mine satisfies scenario (1), where the director directed a single movie and that single movie has multiple actors with the same birth year
Would appreciate advice on how I can improve on my search. Thank you!
Solved! Go to Solution.
09-28-2021 01:38 PM
In general I don't think you syntax is convoluted, just the pattern is expressed like that.
To generalize you can do also:
MATCH (p:Person)-[:ACTED_IN]->(:Movie)<-[:DIRECTED]-(d:Person)
WITH d, p.born as attribute, count(*) as count, collect(p) as people
WHERE count > 1
RETURN d, people, count
I.e. match one half of the pattern and then aggregate on the property, and select all results that exceed your overlap count.
09-28-2021 01:38 PM
In general I don't think you syntax is convoluted, just the pattern is expressed like that.
To generalize you can do also:
MATCH (p:Person)-[:ACTED_IN]->(:Movie)<-[:DIRECTED]-(d:Person)
WITH d, p.born as attribute, count(*) as count, collect(p) as people
WHERE count > 1
RETURN d, people, count
I.e. match one half of the pattern and then aggregate on the property, and select all results that exceed your overlap count.
09-29-2021 02:08 AM
Thank you! Your suggestion is helpful in allowing me to see the output in a clearer manner indeed.
All the sessions of the conference are now available online