【发布时间】:2014-03-06 05:54:59
【问题描述】:
我有一个这样的查询:
MATCH (a)-[:Shout]->(b)
WHERE a.user_id=1
WITH b.post_id as b_post_id, a, b.post as b_post
MATCH (a)-[:Friend]->(c)-[:Shout]->(d)
WITH d.post_id as d_post_id, b_post_id, d.post as d_post, b_post
order by d_post_id desc, b_post_id desc
RETURN collect(distinct d_post) + collect(distinct b_post) as p
我想返回来自用户和朋友的所有帖子,所以我将 2 匹配
第一个匹配 (a)-[:Shout]->(b) 将返回用户的帖子,第二个匹配 (a)-[:Friend]->(c)-[:Shout]->(d) 将返回来自朋友的帖子。
(a)-[:Shout]->(b)的帖子是
post_id: 5, post: nana
post_id: 2, post: hi
(a)-[:Friend]->(c)-[:Shout]->(d)的帖子是
post_id: 6, post: lala
post_id: 4, post: hello
post_id: 3, post: hanson
所以,当我RETURN collect(distinct d_post) + collect(distinct b_post) as p 时,它将是
P: nana, hi, lala, hello, hanson
应该是:lala, nana, hello, hanson, hi 或 6,5,4,3,2
请帮助我。 谢谢。
【问题讨论】:
标签: neo4j sql-order-by match cypher collect