0
votes

I've got a sub graph, of node type c which has a relationship to t1 and t2. Node t1 has a relationship with w1 and w2. Node t2 has a relationship with w1.

What I want to query with cypher is from node c return the w nodes that have 2 or more t nodes related. ie w1 only.

Apparently you can't aggregate in the WHERE clause like

START c=node(7)  
MATCH (c)-[:T_TO]-(t)-[:W_TO]-(w)
WHERE COUNT(t) >= 2
RETURN w.WName;

Maybe looking at it another way, this doesn't work either as I only want the w's that only relate to t1 and t2...?

START c=node(7), t1=node(10), t2=node(8)
MATCH (c)-[:T_TO]-(t)-[:W_TO]-(w)
WHERE t in [t1, t2]
RETURN t, w.WName;

Update Anyone wanting something like the second one, this works:

START c=node(7), t1=node(8), t2=node(10) 
MATCH (c)-[:T_TO]-(t1)-[:W_TO]-(w),(c)-[:T_TO]-(t2)-[:W_TO]-(w) 
RETURN w.WName;
1

1 Answers

1
votes

How about

START c=node(7)  
MATCH (c)-[:T_TO]-(t)-[:W_TO]-(w)
WITH COUNT(t) as tCount,w
WHERE tCount >= 2
RETURN w.WName;