0

我正在对我的 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))

如果有人知道如何处理这个,请告诉我;)

提前谢谢,干杯!

4

1 回答 1

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
于 2017-05-25T13:42:55.090 回答