2

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

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

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

4

2 回答 2

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
于 2013-07-30T14:22:53.737 回答
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

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

那是你想要得到的吗?

于 2013-07-30T04:27:20.300 回答