LIMIT 可以将别名中的前 N 行数据保留,将其余行舍弃。
语法:limit <N>
参数:
- <N>:保留的行数,-1 时保留所有数据行
例如,将模板查询得到的 1~2 步路径 path 的前 2 行保留:
find().nodes([1, 5]) as nodes
n(nodes).e()[:2].n() as path
limit 2
return path
注意子句 LIMIT 和链式命令参数 .limit()
的区别,.limit()
保留的是 path 中每个子查询(单次查询)结果的前 2 行,而不是整个数据流 path 的前 2 行:
find().nodes([1, 5]) as nodes
n(nodes).e()[:2].n().limit(2) as path
return path
示例图集:(以下示例将在本图基础上运行)
在空图集中依次运行以下各行代码以创建该图数据:create().node_schema("student").node_schema("course")
create().node_property(@*, "name").node_property(@student, "age", int32).node_property(@course, "credit", int32)
insert().into(@student).nodes([{_id:"S001", _uuid:1, name:"Jason", age:25}, {_id:"S002", _uuid:2, name:"Lina", age:23}, {_id:"S003", _uuid:3, name:"Eric", age:24}, {_id:"S004", _uuid:4, name:"Emma", age:26}, {_id:"S005", _uuid:5, name:"Pepe", age:24}])
insert().into(@course).nodes([{_id:"C001", _uuid:6, name:"French", credit:4}, {_id:"C002", _uuid:7, name:"Math", credit:5}])
insert().into(@default).edges([{_uuid:1, _from_uuid:1, _to_uuid:6}, {_uuid:2, _from_uuid:2, _to_uuid:6}, {_uuid:3, _from_uuid:3, _to_uuid:6}, {_uuid:4, _from_uuid:2, _to_uuid:7}, {_uuid:5, _from_uuid:3, _to_uuid:7}, {_uuid:6, _from_uuid:4, _to_uuid:7}, {_uuid:7, _from_uuid:5, _to_uuid:7}])
一般用法
示例:查找 3 个年龄最大 @student 点,返回 name
find().nodes({@student}) as n
order by n.age desc
limit 3
return n.name
Emma
Jason
Pepe