数据表中有一列数据,如图所示:
现在需要将该列数据分成三列。
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,c
1例如:要把如图1的字段拆分图2
select account_id,
substring_index(substring_index(a.related_shop_ids,','
,b.help_topic_id+1),',',-1) shopid
from
sales_hang_account a
join
mysql.help_topic b
on b.help_topic_id < (length(a.related_shop_