为什么 WITH 子句需要提醒 Cypher 中的变量?

Why does the `WITH` clause need to be reminded about the variable in Cypher?

group 中说 属性 我有值 cat dogchicken egg。我想将 属性 gid 中值的初始字符分配给 group,即 cdce。这是我的查询:

match (n) 
with split(n.group," ") as array 
set n.gid=left(array[0],1)+left(array[1],1) 
return n.name, n.gid;

我收到这个错误:

Variable `n` not defined (line 2, column 48 (offset: 48))
"match (n) with split(n.group," ") as array set n.gid=left(array[0],1)+left(array[1],1) return n.name, n.gid;"
                                                ^

但是,这有效:

match (n) 
with n, split(n.group," ") as array 
set n.gid=left(array[0],1)+left(array[1],1) 
return n.name, n.gid;

我不明白这是为什么?我查看了 WITH 文档,但没有发现任何问题?

来自 WITH 文档本身

It is important to note that WITH affects variables in scope. Any variables not included in the WITH clause are not carried over to the rest of the query.

在第一个查询中,

match (n) 
with split(n.group," ") as array 
...

只有 array 被转移到查询的其余部分,n 被遗忘了。这就是你得到错误的原因。