我在Neo4j图表上做了一些分析,并且知道我遇到了另一个问题。 我的工作查询如下:
MATCH p=allShortestPaths((source:Person)-[:KNOWS*]-(target:Person))
WHERE id(source) < id(target) and length(p) > 1
UNWIND nodes(p)[1..-1] AS n
RETURN n.id AS id, n.firstname AS firstname, n.lastname AS lastname, count(*) as betweenness
ORDER BY betweenness DESC
这可以按预期工作,并给我一个这样的列表:
到目前为止,这么好。但是现在我想要一个额外的列,其中显示基于所有最短路径的百分比值。
我曾尝试简单地添加100.0 * SUM(betweenness) / count(p) AS percent
,但这会导致错误变量betweenness
未定义(第4行,第119栏(偏移:267))
如果有人知道如何处理,请告诉我;)
提前谢谢,干杯!答案 0 :(得分:0)
使用WITH:
p
以及下一个上下文的其他属性。betweenness
计算percent
并返回全部。试一试:
MATCH p=allShortestPaths((source:Person)-[:KNOWS*]-(target:Person))
WHERE id(source) < id(target) and length(p) > 1
UNWIND nodes(p)[1..-1] AS n
WITH p, n.id AS id, n.firstname AS firstname, n.lastname AS lastname, count(*) as betweenness
RETURN id, firstname, lastname, betweenness, 100.0 * SUM(betweenness) / count(p) AS percent
ORDER BY betweenness DESC