ORDER BY子查询的UNION结果 [英] ORDER BY the result of UNION of subqueries

查看:74
本文介绍了ORDER BY子查询的UNION结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想计算 UNION 多个子查询,然后使用 ORDER BY 对结果进行排序.

I would like to compute the UNION of multiple subqueries and sort the result using ORDER BY.

所以我想运行此查询(用伪密码编写):

So I'd like to run this query (written in pseudo-Cypher):

(RETURN 2 AS x
UNION
RETURN 1 AS x)
ORDER BY x

并获得以下结果:

╒═══╕
│x  │
╞═══╡
│1  │
├───┤
│2  │
└───┘

有没有办法做到这一点?由于ORDER BY始终与单个 WITH / RETURN 子句,我没有认为这是可能的,我也想不到一个好的解决方法.

Is there a way to do this? As ORDER BY is always tied to a single WITH/RETURN clause, I do not think this is possible, nor can I think of a good workaround.

推荐答案

Cypher语言尚不支持

The Cypher language does not yet support Post-Union processing.

但是,作为一种解决方法,您应该能够使用APOC过程 apoc.cypher.run 以在子例程"中执行UNION操作,然后在主Cypher查询中执行UNION后处理.例如:

However, as a workaround, you should be able to use the APOC procedure apoc.cypher.run to perform the UNION operation in a "subroutine", and then perform the post-UNION processing in the main Cypher query. For example:

CALL apoc.cypher.run("RETURN 2 AS x UNION RETURN 1 AS x", NULL) YIELD value
RETURN value.x AS x
ORDER BY x;

更新:现在可以在Neo4j 4.0中使用 CALL {subquery}构造.

Update: this is now possible in Neo4j 4.0 using the CALL {subquery} construct.

这篇关于ORDER BY子查询的UNION结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆