- nebula 版本:3.2.0
- 部署方式:分布式
- 安装方式:Docker
- 是否为线上版本:N
- 问题的具体描述:
对两个 MATCH 结果集进行 UNION、INTERSECT、MINUS 操作之后如何统计结果数
,在 2.0.0 版本中,可通过 (MATCH (expression) UNION MATCH(expression)) | YIELD COUNT(*) 来实现,在 3.2.0 这个语法不支持,有其他的方式实现吗
1 个赞
如果不是 count,直接可以用 UNION
MATCH (n:player)
RETURN n.player.name AS name
UNION
MATCH (n:team)
RETURN n.team.name AS name
+-------------------------+
| name |
+-------------------------+
| "Vince Carter" |
| "Giannis Antetokounmpo" |
| "Damian Lillard" |
| "Dwight Howard" |
| "Amar'e Stoudemire" |
| "Jason Kidd" |
| "Rudy Gay" |
| "Dejounte Murray" |
| "Chris Paul" |
| "Carmelo Anthony" |
| "Joel Embiid" |
| "Steve Nash" |
| "Rajon Rondo" |
| "Boris Diaw" |
| "DeAndre Jordan" |
| "Ricky Rubio" |
| "Marc Gasol" |
| "Klay Thompson" |
| "JaVale McGee" |
| "Danny Green" |
| "Tiago Splitter" |
| "David West" |
| "Russell Westbrook" |
| "Kristaps Porzingis" |
| "Tim Duncan" |
| "Tony Parker" |
| "Cory Joseph" |
| "Kyrie Irving" |
| "Paul George" |
| "Yao Ming" |
| "Grant Hill" |
| "Jonathon Simmons" |
| "Stephen Curry" |
| "Kevin Durant" |
| "Blake Griffin" |
| "Ray Allen" |
| "Shaquille O'Neal" |
| "Ben Simmons" |
| "LaMarcus Aldridge" |
| "Kyle Anderson" |
| "Kobe Bryant" |
| "Dwyane Wade" |
| "Paul Gasol" |
| "Tracy McGrady" |
| "Luka Doncic" |
| "Marco Belinelli" |
| "Aron Baynes" |
| "LeBron James" |
| "James Harden" |
| "Manu Ginobili" |
| "Dirk Nowitzki" |
| "76ers" |
| "Jazz" |
| "Lakers" |
| "Nets" |
| "Hornets" |
| "Mavericks" |
| "Thunders" |
| "Suns" |
| "Wizards" |
| "Bulls" |
| "Clippers" |
| "Hawks" |
| "Pelicans" |
| "Cavaliers" |
| "Celtics" |
| "Kings" |
| "Knicks" |
| "Pistons" |
| "Rockets" |
| "Grizzlies" |
| "Nuggets" |
| "Bucks" |
| "Magic" |
| "Timberwolves" |
| "Heat" |
| "Raptors" |
| "Spurs" |
| "Pacers" |
| "Trail Blazers" |
| "Warriors" |
+-------------------------+
Got 81 rows (time spent 5820/12535 us)
如果需要给结果再处理(比如count),就有点麻烦,不能用集合运算符号,而是用多 MATCH 和 WITH处理。
这里是并集的例子(如果是交集,minus,需要把列表转换为 set 再处理,这里并集我就先列表 + 再去重了)
MATCH (p:player)
WITH collect(p.player.name) AS players
MATCH (t:team)
WITH players + collect(t.team.name) AS playersAndTeamsList
UNWIND playersAndTeamsList AS result
RETURN count(DISTINCT result)
+------------------------+
| count(distinct result) |
+------------------------+
| 81 |
+------------------------+
2 个赞
此话题已在最后回复的 7 天后被自动关闭。不再允许新回复。