Neo4j 简明教程
Neo4j - Limit Clause
limit 子句用于限制输出中的行数。
The limit clause is used to limit the number of rows in the output.
Syntax
以下为 LIMIT 子句的语法。
Following is the syntax of the LIMIT clause.
MATCH (n)
RETURN n
ORDER BY n.name
LIMIT 3
Example
在继续举例之前,请按照以下指示在 Neo4j 数据库中创建 5 个节点。
Before proceeding with the example, create 5 nodes in the Neo4j database as shown below.
CREATE(Dhawan:player{name:"shikar Dhawan", YOB: 1985, runs:363, country: "India"})
CREATE(Jonathan:player{name:"Jonathan Trott", YOB:1981, runs:229, country:"South Africa"})
CREATE(Sangakkara:player{name:"Kumar Sangakkara", YOB:1977, runs:222, country:"Srilanka"})
CREATE(Rohit:player{name:"Rohit Sharma", YOB: 1987, runs:177, country:"India"})
CREATE(Virat:player{name:"Virat Kohli", YOB: 1988, runs:176, country:"India"})
以下是一个示例 Cypher 查询,该查询按降序返回上述创建的节点,并将其结果中的记录限制为 3 个。
Following is a sample Cypher Query which returns the nodes created above in a descending order and limits the records in the result to 3.
MATCH (n)
RETURN n.name, n.runs
ORDER BY n.runs DESC
LIMIT 3
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.

Limit with expression
您还可以对表达式使用 LIMIT 子句。
You can also use the LIMIT clause with expression.
Example
以下是限制使用表达式记录的 Cypher 查询示例。
Following is a sample Cypher Query which limits the records using an expression.
MATCH (n)
RETURN n.name, n.runs
ORDER BY n.runs DESC
LIMIT toInt(3 * rand())+ 1
执行上述查询,执行以下步骤:
To execute the above query, carry out the following steps −
Step 1 - 打开 Neo4j Desktop App 并启动 Neo4j Server。使用 URL http://localhost:7474/ 打开 Neo4j 的内置浏览器应用,如下面的屏幕截图所示。
Step 1 − Open the Neo4j desktop App and start the Neo4j Server. Open the built-in browser app of Neo4j using the URL http://localhost:7474/ as shown in the following screenshot.

Step 2 - 在美元提示符中复制并粘贴所需的查询,并按播放按钮(执行查询)突出显示在下面的屏幕截图中。
Step 2 − Copy and paste the desired query in the dollar prompt and press the play button (to execute the query) highlighted in the following screenshot.
