数据表中有一列数据,如图1所示: 图1数据表 现在需要将该列数据分成三列。 sql 代码如下所示: 1、 select max(case when F1%3=1 then F1 else 0 end) a,max(case w
数据表中有一列数据,如图1所示:
图1数据表
现在需要将该列数据分成三列。
sql 代码如下所示:
1、
select
max(case when F1%3=1 then F1 else 0 end) a,
max(case when F1%3=2 then F1 else 0 end) b,
max(case when F1%3=0 then F1 else 0 end) c
from HLR151
group by (F1-1)/3
效果:
2、
select
c1=a.F1,c2=b.F1,c3=c.F1
from HLR151 a
left join HLR151 b on b.F1=a.F1+1
left join HLR151 c on c.F1=a.F1+2
where (a.F1-1)%3=0
效果:
select
max(case when (F1-1)/8=0 then F1 else 0 end) a,
max(case when (F1-1)/8=1 then F1 else 0 end) b,
max(case when (F1-1)/8=2 then F1 else 0 end) c
from HLR151
group by (F1-1)%8
效果:
转自:https://www.cnblogs.com/shuai/arcHive/2011/02/16/1956123.html
【转】SQL Server将一列拆分成多列
原文地址:Https://www.cnblogs.com/hycms/p/13307602.html
--结束END--
本文标题: 【转】SQL Server将一列拆分成多列
本文链接: https://www.lsjlt.com/news/7179.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
2024-05-14
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0