所以我使用SQLite,并有一个3列的表。 第一列填充数据,另外两列当前包含空值。
我想获取第一列中的文本,将其拆分,并使用此文本填充第2列和第3列。
例如在我们的第一行中,column1包含文本'NORTH / SOUTH'。 现在我想在第2列中加上'NORTH'字样,在第3列中加上'SOUTH'字样。 我想对表中的所有行执行此操作,将第1列中的文本拆分并使用它填充第2列和第3列。
我可以仅使用SQLite和SQL命令吗? 或者我需要使用其他软件或编程语言吗? 关于所需实际代码的建议也很棒。
任何帮助赞赏。
So I'm using SQLite and have a table with 3 columns. The first column is populated with data and the other 2 columns currently contain null values.
I want to take the text in the first column, split it up, and populate columns 2 and 3 with this text.
E.g. in our first row, column1 contains the text 'NORTH/SOUTH'. Now I want to put the word 'NORTH' in column2 and the word 'SOUTH' in column3. I want to do this for all rows in the table, splitting up the text in column1 and using it to populate columns 2 and 3.
Can I do this merely using SQLite and SQL commands? Or do I need to use other software or programming languages? Advice on the actual code required would be awesome too.
Any help appreciated.
最满意答案
根据您提供的数据,请尝试以下查询:
UPDATE table SET column_2 = substr(col1,1,INSTR(col1,'/')), column_3 = substr(col1,INSTR(col1,'/'),length(col1));As per your given data, Try with this query:
UPDATE table SET column_2 = substr(col1,1,INSTR(col1,'/')), column_3 = substr(col1,INSTR(col1,'/'),length(col1));根据另一列的值填充列(SQL)(Populating a column based on value of another column (SQL))所以我使用SQLite,并有一个3列的表。 第一列填充数据,另外两列当前包含空值。
我想获取第一列中的文本,将其拆分,并使用此文本填充第2列和第3列。
例如在我们的第一行中,column1包含文本'NORTH / SOUTH'。 现在我想在第2列中加上'NORTH'字样,在第3列中加上'SOUTH'字样。 我想对表中的所有行执行此操作,将第1列中的文本拆分并使用它填充第2列和第3列。
我可以仅使用SQLite和SQL命令吗? 或者我需要使用其他软件或编程语言吗? 关于所需实际代码的建议也很棒。
任何帮助赞赏。
So I'm using SQLite and have a table with 3 columns. The first column is populated with data and the other 2 columns currently contain null values.
I want to take the text in the first column, split it up, and populate columns 2 and 3 with this text.
E.g. in our first row, column1 contains the text 'NORTH/SOUTH'. Now I want to put the word 'NORTH' in column2 and the word 'SOUTH' in column3. I want to do this for all rows in the table, splitting up the text in column1 and using it to populate columns 2 and 3.
Can I do this merely using SQLite and SQL commands? Or do I need to use other software or programming languages? Advice on the actual code required would be awesome too.
Any help appreciated.
最满意答案
根据您提供的数据,请尝试以下查询:
UPDATE table SET column_2 = substr(col1,1,INSTR(col1,'/')), column_3 = substr(col1,INSTR(col1,'/'),length(col1));As per your given data, Try with this query:
UPDATE table SET column_2 = substr(col1,1,INSTR(col1,'/')), column_3 = substr(col1,INSTR(col1,'/'),length(col1));
发布评论