Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Neo4j 在路径中查找平均年龄的密码查询_Neo4j - Fatal编程技术网

Neo4j 在路径中查找平均年龄的密码查询

Neo4j 在路径中查找平均年龄的密码查询,neo4j,Neo4j,在下面的查询中,我如何查找路径中用户的平均年龄: start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32") match p = begin--()--end return extract(n in nodes(p): n.Age); 在cypher 1.8中,仅修复第一个查询: start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_3

在下面的查询中,我如何查找路径中用户的平均年龄:

start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")

match p = begin--()--end

return extract(n in nodes(p): n.Age);

在cypher 1.8中,仅修复第一个查询:

start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match begin--middle--end
where has(middle.Age)
return sum(middle.Age) / count(middle);
但是,我相信您要求从用户2到用户32的所有用户:

start n=node(*)
where has(n.Age) and Id(n)>1 and Id(n)<33
return sum(n.Age) / count(n);

编辑:我刚刚发现您可以替换总和(n.Age)/count(n);只需使用cypher 1.8中的avg(n.Age)

即可修复您的第一个查询:

start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match begin--middle--end
where has(middle.Age)
return sum(middle.Age) / count(middle);
但是,我相信您要求从用户2到用户32的所有用户:

start n=node(*)
where has(n.Age) and Id(n)>1 and Id(n)<33
return sum(n.Age) / count(n);

编辑:我刚刚发现您可以替换总和(n.Age)/count(n);只需使用avg(n.Age)

即可,在1.9中,您现在可以使用
reduce
实现这一点

start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match p = begin--()--end
return reduce(total=0, n in nodes(p): total + n.Age) / length(p) as avgAge;

因此,在1.9中,您现在可以使用
reduce
执行此操作

start begin=node:Nodes(Name="User_2"), end=node:Nodes(Name="User_32")
match p = begin--()--end
return reduce(total=0, n in nodes(p): total + n.Age) / length(p) as avgAge;

这不是路径上的平均年龄,而是结果集上的平均年龄。这不是路径上的平均年龄,而是结果集上的平均年龄。