1, 创建测试表
create table
t
as
select 'china' col_1,'america' col_2,'canada' col_3,-1 status from dual
union all
select '花生','瓜子','绿豆',0 from dual
union all
select '牙膏','牙刷','杯子',3 from dual
union all
select '芍药','牡丹','月季',1 from dual
union all
select '优乐美','香飘飘','炸鸡',2 from dual;
2, 在一张表中测试
--可以在一张表中测试
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
);
2, 在多张表中做测试
--union跨表排序查询
select total.* from
(
select t.* from (select col_1, col_2, col_3, status from t order by status) t
union all
select t2.* from (select col_1, col_2, col_3, status from t2 order by status) t2
) total
order by total.status;
推荐学习网页网址: http://blog.youkuaiyun.com/bobo12082119/article/details/6323727#plain
有个问题:
项目中需要跨表排序查询的时候是不是用第二种测试方法?
如果不是
那有没有更好得实现跨表排序查询的方法?
如果有人知道请留言,很愿意跟大家交流,共同学习!