返回

本页描述如何使用 Cypher®.Return 类创建一个 RETURN 子句。

可以使用 new Cypher.Return 添加 RETURN 子句。不过,更常见的做法是先有一个已有子句(例如 MATCH),然后通过 .return 方法添加。在这两种情况下,返回的变量都可以作为参数传入。

const node = new Cypher.Node();
const returnQuery = new Cypher.Return(node, new Cypher.Literal(10));

这将生成以下的 RETURN 子句

RETURN this0, 10

任何表达式都可以作为返回值传入,例如函数

const returnQuery = new Cypher.Return(Cypher.round(new Cypher.Param(2.3)));

这相当于

RETURN round($param1)

结果别名

可以通过使用包含两个元素的数组为结果设置别名——变量本身和别名名称,别名可以是字符串或变量。

const node = new Cypher.Node();
const returnQuery = new Cypher.Return([node, "my-node"]);

这将生成以下子句

RETURN this0 AS my-node

唯一结果

使用 .distinct 方法在 RETURN 中添加 DISTINCT

const returnQuery = new Cypher.Return(node).distinct();

这将生成以下子句

RETURN DISTINCT this0
© . This site is unofficial and not affiliated with Neo4j, Inc.