declare @table table (name nvarchar(4))
insert into @table
select '張三' union all
select '李四' union all
select '王五' union all
select '劉三' union all
select '楊二' union all
select '胡八' union all
select '趙六'
--方法1:
create table #t (id int identity(1,1),name nvarchar(4))
insert into #t(name) select * from @table
select a.name,b.name from #t a left join #t b on a.id=b.id-1 where a.id%2<>0
drop table #t
--方法2:
select identity(int, 1,1) AS id ,name
into #tt
from @table
select a.name, b.name
from #tt a left join #tt b on a.id = b.id-1
where a.id %2 <> 0
drop table #tt
其實是同一個方法.
本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。