如何将这些记录分为单个新记录?
我想搜索列中是否存在一个字符串(site_id
),然后将该字符串放在新表中,并在该行中具有其前列的值。该表只有2列,site_id
列可能具有我想要的许多5字字符串。
我想获取所有特定站点ID。例如:e7089或e7459(我需要所有这些,第一个单词是随机的,例如e或t或etc,而四个数字是可变的)。
第一行是一个ticket_id
和许多site_id
s。我只需要以下网站ID,例如:G1231或G1236,而不需要括号中的地址:
ticket_id | site_id |
---|---|
sss sss-bb-12312312-12312 | G1231(AFSDGF-SDGSDGDG) B3213(ASDFSDF) |
并这样做:
ticket_id | site_id |
---|---|
sss bb-12312312-12312 | G1231 |
SSS-BB | G3212 |
- | , |
2312- | 12312312-12312 |
G3212 12312 | B3213 |
我可以找到带有Regexp [AZ] \ d {1,4}
的5字站点ID,但是我无法将其提取并插入新行。我的代码:
DROP TABLE IF EXISTS test2;
CREATE TABLE if NOT EXISTS test2
(
Ticket_id varchar,
site_id varchar
);
INSERT INTO test2
SELECT ticket_id, site_id
FROM TEST
WHERE site_id regexp '[A-Z]\d{1,4}';
这将找到site_id
的s并插入匹配的行。我不要那个。如何将第一个转换为第二个?
当前数据库:
Comart1 | Column2 |
---|---|
Ticket1 | 许多站点IDS |
Ticket2 | 许多站点ID |
我想要的是:
Column1 | County2 |
---|---|
Ticket1 | ID |
Ticket1 ID Ticket1 ID Ticket1 | ID |
Ticket1 | ID |
Ticket1 | ID Ticket2 ID |
Ticket2 | ID |
Ticket2 | ID |
Ticket2 | ID |
- 票证不需要任何更改,除了与他们的新行复制为新行分配的
site_id
。 - 每个机票都有多个
site_id
s,需要将需要分开为新行。 - 需要在SQLite DB浏览器中完成(不幸的是没有Python)。
I want to search if a string exists in column2 (site_id
) then put that string in a new table with the value of its before column in that row. The table has only 2 columns and the site_id
column may have many 5-word strings that I want.
I want to get all of the the specific site id's. For example: E7089 or E7459 (I need all of them and the first word is random like E or T or etc and the four digits are variable).
The first row is with one ticket_id
and many site_id
s. I only need site ids like:g1231 or g1236 and not the addresses in parentheses:
ticket_id | site_id |
---|---|
sss-bb-12312312-12312 | g1231(afsdgf-sdgsdgdg), g1236(sdfsdgsdg), g3212(asdfas-dfsd), b2311(asdasd), b3213(asdfsdf) |
And make it like this:
ticket_id | site_id |
---|---|
sss-bb-12312312-12312 | g1231 |
sss-bb-12312312-12312 | g3211 |
sss-bb-12312312-12312 | g1236 |
sss-bb-12312312-12312 | b2311 |
sss-bb-12312312-12312 | b3213 |
I can find the 5-word site id's with regexp [A-Z]\d{1,4}
, but I can't extract and insert them into a new row. My code :
DROP TABLE IF EXISTS test2;
CREATE TABLE if NOT EXISTS test2
(
Ticket_id varchar,
site_id varchar
);
INSERT INTO test2
SELECT ticket_id, site_id
FROM TEST
WHERE site_id regexp '[A-Z]\d{1,4}';
This will find the site_id
's and insert rows that match. I don't want that. How to convert the first one to the second?
Current db :
column1 | column2 |
---|---|
ticket1 | many site ids |
ticket2 | many site ids |
I want it to be :
column1 | column2 |
---|---|
ticket1 | id |
ticket1 | id |
ticket1 | id |
ticket1 | id |
ticket2 | id |
ticket2 | id |
ticket2 | id |
- The tickets do not need any change except getting copied into new rows with their assigned
site_id
. - There are multiple
site_id
s for each ticket that need to be separated to new rows. - It needs to be done in SQLite db browser (unfortunately no Python).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要一个递归的CTE来拆分表表
test1
和substr()函数的列,以获取前5个字符以插入表test2 :
请参阅
You need a recursive CTE to split the
site_id
column of the tabletest1
and SUBSTR() function to take the first 5 chars to insert in the tabletest2
:See the demo.