首页 > 数据库技术 > 详细

sql中一列拆成两列

时间:2017-05-11 23:31:42      阅读:307      评论:0      收藏:0      [点我收藏+]

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

其实是同一个方法.

sql中一列拆成两列

原文:http://www.cnblogs.com/lgx5/p/6842815.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!