Damian Grzanka
Damian Grzanka

Reputation: 305

Most sort by mutual relationships neo4j

I want to create a query in cypher but I have problems with one part this is how it should look

Example Graph

Upvotes: 0

Views: 40

Answers (1)

cybersam
cybersam

Reputation: 66989

The aggregating function COUNT should help. Something like this:

MATCH (t1:Thread)<-[:USED]-(u:User)-[:USED]->(t2:Thread)
WHERE t1.id = 123
RETURN t1, t2, COUNT(DISTINCT u) AS cnt
ORDER BY cnt DESC

The DISTINCT option, which incurs overhead, should only be used if it is possible for a User to be related to the same pair of threads multiple times.

Upvotes: 1

Related Questions