UNWINDGraph
UNWIND
语句可以将列表拆分为单独的行,列表中的每个元素为一行。
UNWIND
可以作为单独语句或语句中的子句使用。
语法Graph
UNWIND <list> AS <alias> <RETURN clause>
拆分列表Graph
nebula) [basketballplayer]> UNWIND [1,2,3] AS n RETURN n;
+---+
| n |
+---+
| 1 |
+---+
| 2 |
+---+
| 3 |
+---+
返回去重列表Graph
在UNWIND
语句中使用WITH DISTINCT
可以将列表中的重复项忽略,返回去重后的结果。
示例1Graph
- 拆分列表
[1,1,2,2,3,3]
。 - 删除重复行。
- 排序行。
- 将行转换为列表。
nebula> WITH [1,1,2,2,3,3] AS n \
UNWIND n AS r \
WITH DISTINCT r AS r \
ORDER BY r \
RETURN collect(r);
+------------+
| COLLECT(r) |
+------------+
| [1, 2, 3] |
+------------+
示例2Graph
- 将匹配路径上的顶点输出到列表中。
- 拆分列表。
- 删除重复行。
- 将行转换为列表。
nebula> MATCH p=(v:player{name:"Tim Duncan"})--(v2) \
WITH nodes(p) AS n \
UNWIND n AS r \
WITH DISTINCT r AS r \
RETURN collect(r);
+----------------------------------------------------------------------------------------------------------------------+
| COLLECT(r) |
+----------------------------------------------------------------------------------------------------------------------+
| [("player100" :player{age: 42, name: "Tim Duncan"}), ("player101" :player{age: 36, name: "Tony Parker"}),
("team204" :team{name: "Spurs"}), ("player102" :player{age: 33, name: "LaMarcus Aldridge"}),
("player125" :player{age: 41, name: "Manu Ginobili"}), ("player104" :player{age: 32, name: "Marco Belinelli"}),
("player144" :player{age: 47, name: "Shaquile O'Neal"}), ("player105" :player{age: 31, name: "Danny Green"}),
("player113" :player{age: 29, name: "Dejounte Murray"}), ("player107" :player{age: 32, name: "Aron Baynes"}),
("player109" :player{age: 34, name: "Tiago Splitter"}), ("player108" :player{age: 36, name: "Boris Diaw"})] |
+----------------------------------------------------------------------------------------------------------------------+
最后更新: April 13, 2021