10
2021
12

Mysql GBase 中一行变多行

测试

select  
           substring_index(
              substring_index('1,2,3', ',', 1 + 1), ',', -1) as spitId
              
-- 工具表              
create table tb_number
(
id  int 
);

insert into tb_number(id) values(1);
insert into tb_number(id) values(2);
insert into tb_number(id) values(3);
insert into tb_number(id) values(4);
insert into tb_number(id) values(5);
....

-- 辅助表
create table tb_str
(
str varchar(100)
)

-- 插入一行即可
insert into tb_str(str)values('only one line');



SELECT
      SUBSTRING_INDEX( SUBSTRING_INDEX( '1,2,3', ',', G.ID ), ',',- 1 ) IDS 
  FROM
      tb_str C
      JOIN tb_number G ON G.ID <= ( LENGTH( '1,2,3' ) - LENGTH( REPLACE ( '1,2,3', ',' , '' ) ) + 1 )


« 上一篇 下一篇 »

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。