找到具有最多相互连接节点的节点?

时间:2015-06-04 16:23:54

标签: neo4j cypher

我正在使用包含客户,他们的购买以及他们从中购买的商家的数据集,并且我正在尝试确定哪些企业共享最多的共同客户。理想情况下,输出将是一个表格,列出了连接的业务和共同客户的数量。即:

| BUSINESS_1 - BUSINESS_2 | 4 |
| BUSINESS_1 - BUSINESS_5 | 3 |
| BUSINESS_3 - BUSINESS_7 | 2 |
| BUSINESS_4 - BUSINESS_9 | 2 |

我现在没有太多,但我正在使用的查询看起来像这样:

MATCH (c:Customer)<-[:Trans_Cust]-(t:Transaction)-[:Trans_Business]->(b:Business)
RETURN c, t, b

提前致谢

1 个答案:

答案 0 :(得分:2)

我想这应该可以解决问题,可能会在http://console.neo4j.org上提供一个示例数据集供我们帮助。

MATCH (b:Business)
MATCH (b)<-[:Trans_Business]-(t:Transaction)-[:Trans_Cust]->(c:Customer)
MATCH (c)<-[:Trans_Cust]-(:Transaction)-[:Trans_Business]->(other:Business)
WHERE b <> other
WITH b, other, collect(distinct(customer)) as customers
RETURN b, other, size(customers) as sharedCustomers
ORDER BY sharedCustomers DESC