Sqlite Create new columns from column containing ;

前端 未结 2 622
孤街浪徒
孤街浪徒 2020-12-21 14:07

I have a database test.db with the first column containing 123456;abcdef;ghijk etc. Is it possible to split the data into its own colums?

<

2条回答
  •  孤城傲影
    2020-12-21 14:15

    You can split your rows into columns by:

    create table t1 as
    select substr(c1,0,instr(c1,';')) as column1, 
           substr(c1,instr(c1,';')+1,instr(c1,';')-1) as column2,
           substr(c1,instr(c1,';')+1+instr(substr(c1,instr(c1,';')+1),';')) as column3
    from table_test;
    

    where c1 is the column you are selecting from.

提交回复
热议问题