create table T(a1 int, a2 int, a3 int)
insert T select 1, 2, 3
union all select 4, 5, 6
union all select 7, 8, 9
union all select 10, 11, 12
select ID=identity(int, 1, 1), * into #T from T
select tmp.a1, tmp.a2, tmp.a3,
a1=(select a1 from #T where ID=tmp.ID+1),
a2=(select a2 from #T where ID=tmp.ID+1),
a3=(select a3 from #T where ID=tmp.ID+1)
from #T tmp
where ID%2=1
declare @a table (id int identity(1,1),a1 int,a2 int ,a3 int)
insert into @a(a1,a2,a3)
select 1,2,3
union all select 4,5,6
union all select 7,8,9
union all select 10,11,12
select * from @a
select sum(case when id%2=1 then a1 else 0 end) as a1,
sum(case when id%2=1 then a2 else 0 end) as a2,
sum(case when id%2=1 then a3 else 0 end) as a3,
sum(case when id%2=0 then a1 else 0 end) as a1,
sum(case when id%2=0 then a2 else 0 end) as a2,
sum(case when id%2=0 then a3 else 0 end) as a3
from @a group by (id+1)/2
create table pp(
id int identity(1,1) not null,
a1 int not null,
a2 int not null,
a3 int not null)
insert into pp(a1,a2,a3) values(1,2,3)
insert into pp(a1,a2,a3) values(4,5,6)
增加一个自动ID号就可以了
insert into pp(a1,a2,a3) values(7,8,9)
insert into pp(a1,a2,a3) values(10,11,12)
select A.a1, A.a2, A.a3,B.a1,B.A2,B.a3 from
(select * from pp where (id+1)%2 = 0) A
left join
(select * from pp where id%2 = 0) B
on A.id + 1 = B.id
--测试删除
drop table pp