我想执行此查询
MATCH (p:Person)-->(s:Startup)
WITH DISTINCT p
MATCH (p)-->(s:Startup)-->(m:Market)
WITH DISTINCT p, s, m, COLLECT(m) as markets
ORDER BY id(s)
RETURN DISTINCT p, COUNT(DISTINCT s) as inv,
COLLECT({id: id(s), markets: markets}) as startups,
count (m) as mctotal
ORDER BY inv DESC
LIMIT 10
但我无法弄清楚为什么它没有正确地与他们的市场聚合创业公司。 这是我查询的结果:
+-----+-----+------------+---------+
| p | inv | startups | mctotal |
+-----+-----+------------+---------+
| p | 11 | id: 1 | 7 |
| | | markets: 1 | |
| | | | |
| | | id: 1 | |
| | | markets: 2 | |
| | | | |
| | | id: 2 | |
| | | markets: 3 | |
| | | | |
| | | id: 2 | |
| | | markets: 4 | |
......等等。
我想获得的结果如下:
+-----+-----+---------------+---------+
| p | inv | startups | mctotal |
+-----+-----+---------------+---------+
| p | 11 | id: 1 | 7 |
| | | markets:[1,2] | |
| | | | |
| | | id: 2 | |
| | | markets:[3,4] | |
我希望我清楚要求的是什么。
答案 0 :(得分:1)
这是一个应该更好的变体,你没有分享你的样本图,所以我无法尝试
MATCH (p)-->(s:Startup)-->(m:Market)
WITH p, s, COLLECT(m) as markets, count(m) as mcount
ORDER BY id(s)
RETURN p, COUNT(DISTINCT s) as inv,
COLLECT({id: id(s), markets: markets}) as startups,
sum(mcount) as mctotal
ORDER BY inv DESC
LIMIT 10