简体   繁体   中英

Show all outgoing relationships with cypher for nodes that have more than 1 relationship

I currently have a graph database that has 2 node labels and 1 relationship type.

If i run

MATCH (u)-[r]->(n) return u, n

I can see everything. Some nodes have multiple outgoing relationships. I'd like to filter this view for where nodes have 2 or more outgoing relationships. I tried

MATCH (u)-[r]->(n) with count(r) as c,u,n  where c > 1 return u, n

But this gives me no results. I've seen some answers on here that return just a node, but I want the 2 nodes and the relationship shown. Any ideas?

[EDITED]

This should work:

MATCH (u)-->(n)
WITH u, COLLECT(n) AS ns
WHERE SIZE(ns) > 1
RETURN u, ns

If you specify a set of "grouping keys" with an aggregating function like COLLECT() (in the above query, u is the sole grouping key), then the aggregation is performed over that set of keys.

So, in the above query, COLLECT(n) is collecting al the n nodes for the same u node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM