34,593
社区成员
发帖
与我相关
我的任务
分享
create table tb(a int,id int)
insert into tb
select 1,0 union all
select 2,1 union all
select 3,0 union all
select 4,1 union all
select 5,0
go
select a.a,b.a
from (select a,id as b from tb where id = 0)a
full join
(select a,id as c from tb where id = 1)b
on a.a + 1 = b.a
drop table tb
/*
a a
----------- -----------
1 2
3 4
5 NULL
(3 行受影响)
select
max(case id when 1 then a else '' end ) as b,
max(case id when 0 then a else '' end ) as c
from
tb
select a.a as b,b.a as c
from
(select rn=row_number() over(order by getdate()),a from tb where id=0) a
full join
(select rn=row_number() over(order by getdate()),a from tb where id=1) b
on a.rn=b.rn