我有三个与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
,LIMIT
和ORDER BY
应用于整个结果集,而不是单个查询。我相信这也是它在SQL中的工作方式。但是,我认为Neo4j不是这种情况,因为我可以从desc
中删除ORDER BY
并且订单保持不变。
这是预期的行为吗?有没有办法可以编写查询,以便我可以将SKIP
,LIMIT
和ORDER BY
应用于整个结果集?
我也不确定是否必须在每个子查询中重复行START user=node:User(Id="2")
,因为2.0中的查询可以在没有START子句的情况下启动。我必须重复一遍吗?
关于UNION
关键字,恕我直言,Neo4j文档有点模糊。
答案 0 :(得分:1)
目前尚不支持,因为在此之前需要支持子查询才能正确实现。