Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
07-27-2021 12:43 AM
Have a graph like below, need to find all the paths count from each A to connected C.
How to achieve this?
Expecting below results for the above graph:
A,C,2 (first A,C)
A,C,3 (second A,C)
07-27-2021 01:02 AM
Assuming these have a common label (I'll use :Node), this should be easy enough:
MATCH path = (start:Node {name:'A'})-[:CONNECTED*]->(end:Node {name:'C'})
RETURN count(path) as paths
07-27-2021 03:42 AM
Thank you @andrew.bowman , this will return the overall count.
In my case I have 2 As and 2Cs (They will be connected via some other nodes and relationships, just for the simplicity I have shown as disconnected).
I need to know path count for first A to first C as 2 and second A to second C as 3.
How can I do that?
07-27-2021 08:25 AM
If you include the variables of the start and end nodes along with the count(), then it should aggregate only between the specific nodes:
MATCH path = (start:Node {name:'A'})-[:CONNECTED*]->(end:Node {name:'C'})
RETURN start, end, count(path) as paths
08-09-2021 10:09 PM
Thank you @andrew.bowman ! One more query on similar lines, I have a relationship property called health for each, while finding the path between each A and C, I also need to find the overall health.
In the same graph, the relationship between A and B1 is having health "BAD". Expecting below results, how to do this?
First A & C
Path count: 2
Path1: BAD (from A-B1-C)
Path2: Good(from A-B-C)
Second A & C
Path count: 3
Path1: BAD (from A-B1-C)
Path2: GOOD(from A-B-C)
Path3: GOOD(from A-B-B2-C)
All the sessions of the conference are now available online