我有三个与 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
、 theLIMIT
和ORDER BY
应用于整个结果集,而不是单个查询。我相信这也是它在 SQL 中的工作方式。然而,我认为在 Neo4j 中情况并非如此,因为我可以直接desc
从 中删除,ORDER BY
并且顺序保持不变。
这是预期的行为吗?有没有办法可以编写查询,以便我可以将SKIP
、 theLIMIT
和 theORDER BY
应用于整个结果集?
我也不确定是否必须START user=node:User(Id="2")
在每个子查询中重复该行,因为 2.0 中的查询可以在没有 START 子句的情况下启动。我必须重复吗?
Neo4j 文档对UNION
关键字恕我直言有点含糊。