简体   繁体   中英

Cypher - Issue with Where + Aggregate + With

I am trying to execute the following Cypher query

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

The above query works fine but moment I uncomment lower "with" I get following errors

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

To get around, I include r1 and r2 in the top with - "with b,someone_else_too, count(*) as matchingstuffcount". to "with b, r1, r2, someone_else_too, count(*) as matchingstuffcount". This messes my count(*) > 1 condition as count(*) does not aggregate properly.

Any workarounds / suggestions to filter out count(*) > 1 while making sure Case When can also be executed?

Under neo4j 2.0 via console.neo4j.org I was able to get the following query to work. I tried to mimic the constructs you had, namely the WITH / WHERE / WITH / RETURN sequence. (If I missed something, please let me know!)

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

Update it or change it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM