A.HADDAD
A.HADDAD

Reputation: 1906

Counting the number of relationships foreach Trip

I have a graph database composed with this pattern :

(start)-[:Trip]->(end)

I want to return the number of trips between the start and the end node and that on each different Trip((start)-[r]->(end)).

how to do that in Cypher ?

this is what i have tried :

 MATCH p=(n)-[r]->()
 WITH COLLECT(p) as X
 UNWIND X.r as y
 return count(y)

Update my question

let's suppose Trip =

     (start_node)-[relationship]->(end_node)

example :

(Tunis)-[r1]->(Sfax)
(Tunis)-[r2]->(Sfax)
(Tunis)-[r3]->(Sousse)
(Tunis)-[r4]->(Sousse)
(Tunis)-[r5]->(Sousse)

=> The number of trips between (Tunis) AND (Sfax) is 2

The number of trips between (Tunis) AND (Sousse) is 3

that's what i want.

Upvotes: 0

Views: 256

Answers (1)

logisima
logisima

Reputation: 7478

You just need to use the aggregator operator count :

MATCH (start)-[:Trip]->(end)
RETURN start, end, count(*)

Upvotes: 2

Related Questions