我有两个节点,客户端和生成器。我试图对客户端和构建器之间的关系进行计算,我想将构建器所处的所有连接加起来,但是当他们有20多个客户端访问时,该数量上限为20。例如,如果“ Tim”建筑商有30个客户拜访他,那么他将有20个客户。然后,我需要将每个构建器的客户总数相加,然后取该总数的平均值。到目前为止,这是我的代码:
MERGE (c:Person {csv.name})
MERGE (b:Person {csv.builder})
WITH c, b
MATCH (b:Person)
WITH c, b ,SIZE(()-[:client_of]->(b)) as clientCount
WHERE clientCount > 20
SET clientCount = 20
WITH clientCount, c, b
MATCH (c)-[:client_of]->(b)
RETURN b, avg(sum(clientCount))
https://drive.google.com/file/d/1lYR3KROy7BflN40N18-0B0C9rbNFxHVe/view?usp=sharing这是模拟数据
答案 0 :(得分:0)
这可能会做您想要的(我想这是要插入定义csv
映射的某些Cypher之后的代码段):
MATCH (c:Person {name: csv.name})-[:client_of]->(b:Person {name: csv.builder})
WITH c, SIZE(()-[:client_of]->(b)) as cc
WITH c, CASE WHEN cc > 20 THEN 20 ELSE cc END AS clientCount
RETURN c, AVG(clientCount) AS average;
查询返回Person
提供的名称的csv.name
构建器的平均客户数。没有任何构建器的客户数量大于20。