MySQL修改语句如何让某一字段下以逗号分隔的数字都补齐三位

例如让0,1,2,34变成000,001,002,034

创建表,数据:

create table t
(str varchar(100));

insert into t values ('0,1,2,34');

执行:

SELECT
group_concat(
RIGHT (
concat(
'00',
substring_index(
substring_index(
a.str,
',',
b.help_topic_id + 1
),
',' ,- 1
)
),
3
)
)
FROM
t a
JOIN mysql.help_topic b ON b.help_topic_id < (
length(a.str) - length(REPLACE(a.str, ',', '')) + 1
)

结果:

温馨提示:答案为网友推荐,仅供参考
相似回答