27,579
社区成员
发帖
与我相关
我的任务
分享
select * from (select top 100 percent col1 from a order by col1)a
union all
select * from (select top 100 percent col2 from a order by col2)b
小技巧:这时候如果你想对2输入表分别进行排序,比如上面的#a的a列升序,#b的d列降序,可以这样
select a,b
from (
select *,flag=1 from #a
union all
select *,2 from #b
) l
order by case when flag=1 then a end ,case when flag=2 then b end desc
/*
a b
----------- -----------
5 9
4 9
4 2
3 2
1 2
3 9
4 8
*/