欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

SQL 將一列拆分成多列的三種方法

 更新時間:2020年07月16日 15:39:57   作者:蒼馬之子  
這篇文章主要介紹了SQL 將一列拆分成多列的方法,文中講解非常細致,代碼幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下

數(shù)據(jù)表中有一列數(shù)據(jù),如圖所示:

現(xiàn)在需要將該列數(shù)據(jù)分成三列。

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 將一列拆分成多列的三種方法的詳細內(nèi)容,更多關(guān)于SQL 一列拆分成多列的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

最新評論