我尝试在我在MySQL中使用的h2db中测试我的查询,但我得到一个例外,我的列“名称”未找到。
我的查询如下:
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:未找到列“name”;
如何在h2db中运行此类查询?
提前致谢。
答案 0 :(得分:0)
您的查询在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 uname