数据表中有一列数据,如图所示:
现在需要将该列数据分成三列。
sql 代码如下所示:
第一种
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
效果
第二种
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
效果
以上就是sql 将一列拆分成多列的三种方法的详细内容,更多关于sql 一列拆分成多列的资料请关注<计算机技术网(www.ctvol.com)!!>其它相关文章!
需要了解更多数据库技术:SQL 将一列拆分成多列的三种方法,都可以关注数据库技术分享栏目—计算机技术网(www.ctvol.com)!
本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。
ctvol管理联系方式QQ:251552304
本文章地址:https://www.ctvol.com/dtteaching/630531.html