Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add annotation to some examples of WITH clause #2418

Merged
merged 2 commits into from
Jan 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs-2.0-zh/3.ngql-guide/8.clauses-and-options/with.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
4. 去重后返回点的信息。

```ngql
# 查询 Tag 为 player,name 属性为 Tim Duncan 的点的路径,并返回去重后路径中的所有的点信息列表。
nebula> MATCH p=(v:player{name:"Tim Duncan"})--() \
WITH nodes(p) AS n \
UNWIND n AS n1 \
Expand Down Expand Up @@ -52,6 +53,7 @@ nebula> MATCH p=(v:player{name:"Tim Duncan"})--() \
4. 返回结果。

```ngql
# 查询 id 为 player100 的点,并返回点的所有 Tag。
nebula> MATCH (v) \
WHERE id(v)=="player100" \
WITH labels(v) AS tags_unf \
Expand All @@ -69,6 +71,7 @@ nebula> MATCH (v) \
`WITH`可以在聚合查询中作为过滤器使用。

```ngql
# 查询所有起始点和目的点均有 player 点类型的边,并对所有目的点去重,再根据 age 属性升序排列,返回 age 属性值小于 25 的目的点数据。
nebula> MATCH (v:player)-->(v2:player) \
WITH DISTINCT v2 AS v2, v2.player.age AS Age \
ORDER BY Age \
Expand All @@ -88,6 +91,7 @@ nebula> MATCH (v:player)-->(v2:player) \
在`collect()`函数将输出结果转换为列表之前,可以使用`WITH`子句排序和限制输出结果。

```ngql
# 查询所有 Tag 为 player 的点数据,并根据 name 属性倒序排列,将前 3 条结果转换为列表返回。
nebula> MATCH (v:player) \
WITH v.player.name AS Name \
ORDER BY Name DESC \
Expand All @@ -105,13 +109,15 @@ nebula> MATCH (v:player) \
在`WITH`子句中设置别名,并通过`RETURN`子句输出结果。

```ngql
# 判断 3 是否存在于 list 数组中。
nebula> WITH [1, 2, 3] AS `list` RETURN 3 IN `list` AS r;
+------+
| r |
+------+
| true |
+------+

# 返回 3 和 4 的比较结果。
nebula> WITH 4 AS one, 3 AS two RETURN one > two AS result;
+--------+
| result |
Expand Down