34,590
社区成员
发帖
与我相关
我的任务
分享
--数据如下
create table #a([A] int,[B] int)
go
insert into #a
SELECT 1,2 UNION
SELECT 2,6 UNION
SELECT 3,5 UNION
SELECT 4,3 UNION
SELECT 5,4
select * from #a
select * from #a order by A desc
drop table #a
--如何得到下表 (就是把第二个表里的内容,直接拼到第一个表的后面。)
A B A2 B2
------------------------------
1 2 5 4
2 6 4 3
3 5 3 5
4 3 2 6
5 4 1 2
create table #a([A] int,[B] int)
go
insert into #a
SELECT 1,2 UNION
SELECT 2,6 UNION
SELECT 3,5 UNION
SELECT 4,3 UNION
SELECT 5,4
select *,id=identity(int,1,1) into # from #a
select *,id=identity(int,1,1) into #t from #a order by A desc
select a.a,a.b,b.a as a2,b.b as b2
from # as a full join #t as b on a.id=b.id
drop table #a
drop table #
drop table #t
/*
a b a2 b2
----------- ----------- ----------- -----------
1 2 5 4
2 6 4 3
3 5 3 5
4 3 2 6
5 4 1 2
*/
union all