1

我正在尝试执行以下 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

上面的查询工作正常,但是当我取消注释较低的“with”时,我得到了以下错误

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". to"with b, r1, r2, someone_else_too, count(*) as matchingstuffcount".这会弄乱我的count(*) > 1条件,因为 count(*) 没有正确聚合。

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

4

1 回答 1

0

在通过console.neo4j.org的neo4j 2.0 下,我能够使以下查询正常工作。我试图模仿你的结构,即WITH///序列。(如果我错过了什么,请告诉我!)WHEREWITHRETURN

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

在此处更新或更改。

于 2013-08-19T15:13:48.493 回答