Cypher - Where + Aggregate + With的问题

时间:2013-08-17 19:06:22

标签: cypher

我正在尝试执行以下Cypher查询

START b=node:customer_idx(ID = 'ABCD')   
MATCH p = b-[r1:LIKES]->stuff, someone_else_too-[r2:LIKES]->stuff
with b,someone_else_too, count(*) as matchingstuffcount
where matchingstuffcount > 1
//with   b, someone_else_too, matchingstuffcount, CASE WHEN ...that has r1, r2... END as SortIndex
return someone_else_too, SortIndex
order by SortIndex

上面的查询工作正常,但是当我取消注释时,“我”会出现以下错误

Unknown identifier `b`.
Unknown identifier `someone_else_too`.
Unknown identifier `matchingstuffcount`.
Unknown identifier `r1`.
Unknown identifier `r2`.

为了解决这个问题,我将r1和r2包含在顶部 - "with b,someone_else_too, count(*) as matchingstuffcount"."with b, r1, r2, someone_else_too, count(*) as matchingstuffcount".这会混淆我的count(*) > 1条件,因为count(*)无法正确聚合。

过滤掉count(*)>的任何变通方法/建议1,同时确保Case When也可以执行?

1 个答案:

答案 0 :(得分:0)

在neo4j 2.0下通过console.neo4j.org我能够得到以下查询。我试图模仿你的构造,即WITH / WHERE / WITH / RETURN序列。 (如果我错过了什么,请告诉我!)

START n=node:node_auto_index(name='Neo') 
MATCH n-[r:KNOWS|LOVES*]->m 
WITH n,COUNT(r) AS cnt,m 
WHERE cnt >1 
WITH n, cnt, m,  CASE WHEN m.name?='Cypher'  THEN 1  ELSE 0 END AS isCypher 
RETURN n AS Neo, cnt, m, isCypher 
ORDER BY cnt

更新或更改here