英文:
what is alternative for select string_split('r,a,d,o',',') in mysql
问题
将字符串转换为MySQL中的行。
select id from month_tab where name in (
string_split('jan,feb,mar,may')
);
在上述示例中,我们需要将**string_split('jan,feb,mar,may')** 返回为行。
最终输出应该如下所示
select id from month_tab where name in ('jan','feb','mar','may');
英文:
How to convert a string into rows in MySQL.
select id from month_tab where name in (
string_split('jan,feb,mar,may')
);
In the above example, we need to return string_split('jan,feb,mar,may') as rows.
the final output should be like
select id from month_tab where name in ('jan','feb','mar','may')
);
答案1
得分: 0
You can do it using JSON_TABLE
with cte as (
select 'jan,feb,mar,may' as months
)
select month_tab
from cte
CROSS JOIN JSON_TABLE(CONCAT('["', REPLACE(months, ',','","'), '"]'),
'$[*]' COLUMNS (month_tab TEXT PATH '$')) jsontable;
英文:
You can do it using JSON_TABLE
with cte as (
select 'jan,feb,mar,may' as months
)
select month_tab
from cte
CROSS JOIN JSON_TABLE(CONCAT('["', REPLACE(months, ',', '","'), '"]'),
'$[*]' COLUMNS (month_tab TEXT PATH '$')) jsontable;
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论