3

我有以下查询:

START e1=node:event(prop="0")
MATCH e1-[r:rbel]->e2
WITH e1, e2, count(e1) as ecount
MATCH e1-[:redge]->p<-[:redge]-e2
WITH p.element_type as Type, p.label as Label, (count(p)*100./ecount) as percentage
WHERE percentage > 20
RETURN Type, Label, ROUND(percentage) as Percentage

我正在尝试计算指定模式在 事件中出现的次数占prop="0"这些事件中出现的所有模式的百分比。

我收到以下错误:Unknown identifier 'ecount'

所以我ecount在计算中替换为count(ecount),并且始终得出percentage100% 的 s,我知道这不是真的。

我要解决这个问题了吗?如何将 的值带入ecount子句WITH并将其用于计算?

任何帮助表示赞赏!

4

2 回答 2

4

这个查询对你有用吗?每当我在语句中合并e1and时,总是 1。我认为这是因为当您选择时聚合也不再起作用。要么你省略要么。count(e1)WITHcount(e1)count(e1)e1e1count(e1)

START e1=node:event(prop="0")
MATCH e1-[r:rbel]->e2
WITH e1, e2
MATCH e1-[:redge]->p<-[:redge]-e2
WITH p.element_type as Type, p.label as Label, (count(p)*100./count(e1)) as percentage
WHERE percentage > 20
RETURN Type, Label, ROUND(percentage) as Percentage

更新 在玩弄了您提供的控制台设置之后,我得到了以下查询:

START e1=node:node_auto_index(prop="0") 
MATCH e1-[r:rbel]->e2 
WITH COLLECT(e2) AS e2collection, count(e1) AS cnt 
MATCH e1-[:redge]->p<-[:redge]-(e2) 
WITH p, COLLECT(e1) AS e1collection, cnt, e2collection 
WITH p.name AS Name, cnt, count(p)*100/cnt AS Percentage 
WHERE Percentage > 20 
RETURN Name, Percentage
于 2013-08-27T10:58:41.860 回答
1

h3nrik 的解决方案在下面的控制台设置示例中运行良好,但是,由于某种原因,当应用于我的本地数据浏览器中的实际数据时,它无法正常工作。尽管查询时间较慢,但我发现了以下解决方法:

START e1=node:event(prop="0") 
MATCH e1-[:rbel]->e2 
WITH count(e1) as ecount
START e1=node:event(prop="0") 
MATCH e1-[:rbel]->e2, e1-[:redge]->p<-[:redge]-(e2)
WITH p.label AS Label, p.element_type as Type, ecount, count(p)*100./ecount AS percentage 
WHERE percentage > 20 
RETURN Label, Type, ROUND(percentage) as Percentage
于 2013-08-28T17:23:10.047 回答