博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
sql中一列拆成两列
阅读量:7042 次
发布时间:2019-06-28

本文共 574 字,大约阅读时间需要 1 分钟。

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

其实是同一个方法.

转载地址:http://kqqal.baihongyu.com/

你可能感兴趣的文章
使用 Debian 从 0 开始搭建 hexo 博客
查看>>
Unity C# 计算导弹抛物线弹道和转向
查看>>
区块链技术入门应用
查看>>
一幅图解释区块链结构
查看>>
Service Worker
查看>>
Leaflet-Develop-Guide
查看>>
vue跳转传参刷新后参数消失
查看>>
恭喜 containerd 毕业
查看>>
egg学习笔记-1
查看>>
前端安全问题及解决办法
查看>>
@PropertySource 分环境读取配置
查看>>
Zilliqa网络拓扑
查看>>
GraphQL 的入门指南
查看>>
Tmux的超绝便利 (基础篇)
查看>>
比特球云盘,离线播放云下载探析
查看>>
DCGAN(深度卷积对抗网络)案例
查看>>
进程管理工具Supervisord
查看>>
「 神器 」绝不简单的截图神器
查看>>
FastDFS安装及使用(开山篇)
查看>>
手把手带你把vue+webpack 单页面改多页面(适合上手),支持多级目录
查看>>