有时候,我们会将进过排序(order by)后的结果集与
其他经过排序的结果集进行合并(union or union all)
比如:
select * from tb where length(id)=5 order by id desc
union all
select * from tb where length(id)=10 order by id asc
比如:
select * from tb where length(id)=5 order by id desc
union all
select * from tb where length(id)=10 order by id asc
通常情况下,上面的查询将会得到下面的错误提示:ORA-00933: SQL command not properly ended 错误指向union关键字这里
解决办法:
select * from (
select col_1,col_2,col_3,status
from t
where status >= 0
order by status)
union all
select * from (
select col_1,col_2,col_3,status
from t
where status < 0
order by status)