我试图用我在h2db中使用的MySQL测试我的查询,但是我发现了一个例外,那就是我的专栏"name“没有找到。
我的查询如下:
select t1.name as name, t1.code
from table1 t1
where t1.total > 50
union
select t2.name as name, t2.code
from table2 t2
where t2.total < 50
order by UPPER(name)我有例外
由: org.h2.jdbc.JdbcSQLException:列“名称”未找到;
如何在h2db中运行这样的查询?
提前谢谢。
发布于 2014-05-05 16:20:00
您的查询在MySQL中工作,但在其他数据库(如PostgreSQL )中失败,但有此例外:
ERROR: invalid UNION/INTERSECT/EXCEPT ORDER BY clause
Detail: Only result column names can be used, not expressions or functions.
0A000/0为了兼容性,可以使用以下查询:
select t1.name as name, upper(t1.name) uname, t1.code
from table1 t1
union
select t2.name as name, upper(t2.name) uname, t2.code
from table2 t2
order by unamehttps://stackoverflow.com/questions/23469186
复制相似问题