sqlite数据库多列拆分行,怎么处理

select   '1,2,3,4,5' as  a1 ,'a,b,c,d,e' as a2

SQL 期待遇见you 发布于 2023-5-3 16:28 (编辑于 2023-5-3 16:54)
1min目标场景问卷 立即参与
回答问题
悬赏:0 F币 + 添加悬赏
提示:增加悬赏、完善问题、追问等操作,可使您的问题被置顶,并向所有关注者发送通知
共1回答
最佳回答
0
青春只因年少Lv6中级互助
发布于2023-5-3 17:16(编辑于 2023-5-3 17:30)

//SELECT  * FROM "test"

//drop table if exists test;

//create table test(id int,ids varchar(50));

//insert into test

//select 1,'1,12,135' union all

//select 2,'2,25,234';

---------------------------------------------------------------------------

with split(id,splid,idsstr) as

(

  select  id,'',ids||',' from test    

   UNION ALL 

   SELECT id,substr(idsstr, 0, instr(idsstr, ',')),substr(idsstr, instr(idsstr, ',')+1)

    FROM split WHERE idsstr!=''

  

)

select id,splid  from split

 where splid != ''  

order by id ;

----------------------------------------------------------------------------

引用文章

https://www.jianshu.com/p/6cfc77bb8ff9

  • 2关注人数
  • 322浏览人数
  • 最后回答于:2023-5-3 17:30
    请选择关闭问题的原因
    确定 取消
    返回顶部