4

我有三个与 UNION 子句结合的查询:

CYPHER 2.0
START user=node:User(Id="2")
MATCH (user)-[:FOLLOWS_USER]->()-[:SHARES]->(post)-[?:ORIGINAL]->(original)
WHERE original is null
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
UNION
MATCH (user)-[:FOLLOWS_USER]->()-[:LIKES]->(post)
WITH post, count(post) as likes
WHERE likes >= 0
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
UNION
MATCH (user)-[:FOLLOWS_USER]->()-[:SHARES]->(post)-[repost:ORIGINAL]->()
WITH post, count(repost) as reposts
WHERE reposts >= 0
RETURN distinct post.Id AS Id, post.CreationTime AS CreationTime
ORDER BY post.CreationTime desc
SKIP 0
LIMIT 100;

我希望SKIP、 theLIMITORDER BY应用于整个结果集,而不是单个查询。我相信这也是它在 SQL 中的工作方式。然而,我认为在 Neo4j 中情况并非如此,因为我可以直接desc从 中删除,ORDER BY并且顺序保持不变。

这是预期的行为吗?有没有办法可以编写查询,以便我可以将SKIP、 theLIMIT和 theORDER BY应用于整个结果集?

我也不确定是否必须START user=node:User(Id="2")在每个子查询中重复该行,因为 2.0 中的查询可以在没有 START 子句的情况下启动。我必须重复吗?

Neo4j 文档对UNION关键字恕我直言有点含糊。

4

1 回答 1

1

这尚不支持,因为在此之前需要支持子查询才能正确实现。

于 2013-10-23T10:50:00.823 回答