Cypher Query - 返回每个匹配关系的权重与总权重

时间:2013-07-30 04:06:13

标签: neo4j cypher

我试图在以下示例中找到百分比

START n=node:name_idx(NAME="ABC")
match p = n-[r1:LIKES]->m
with r1.Frequency as Frequency, Sum(r1.Frequency) as Sum
return Frequency, Sum

我希望得到像这样的东西

Frequency        Sum
12               19
6                19
1                19

等等。

我得到的是频率和总和列中的相同值

 Frequency        Sum
    12               12
    6                6
    1                1

有关如何获得正确分发的任何建议吗?我的最终目标是通过划分返回行的频率/总和来找出百分比。谢谢

2 个答案:

答案 0 :(得分:6)

这个怎么样(我偷了Luanne的控制台图):

http://console.neo4j.org/r/3axtkq

START n=node:node_auto_index(name="a") 
MATCH n-[r1:LIKES]->m 
WITH sum(r1.frequency) AS total, n // we want the total... of all frequencies for n
MATCH n-[r1:LIKES]->m              // we need to get the likes again, because those can't be passed in with and get the total of all at the same time
RETURN r1.frequency, total, r1.frequency/(total*1.0) // it does integer math unless you force one to be a float

答案 1 :(得分:2)

查看http://console.neo4j.org/r/voavd2

数据是:

 START n=node(1)
 MATCH n-[r1:LIKES]->m
 RETURN r1,m

您的查询返回:

 START n=node(1)
 MATCH n-[r1:LIKES]->m 
 WITH r1.frequency AS Frequency, Sum(r1.frequency) AS Sum 
 RETURN Frequency, Sum

即。按频率分组,该值的所有频率之和是多少。

这是你想要得到的吗?

相关问题