我有一个选择查询,它带来了8列:
SELECT
substring_index(`Cuisines`,',',1),
substring_index(substring_index(`Cuisines`,',',-7),',',1),
substring_index(substring_index(`Cuisines`,',',-6),',',1),
substring_index(substring_index(`Cuisines`,',',-5),',',1),
substring_index(substring_index(`Cuisines`,',',-4),',',1),
substring_index(substring_index(`Cuisines`,',',-3),',',1),
substring_index(substring_index(`Cuisines`,',',-2),',',1),
substring_index(substring_index(`Cuisines`,',',-1),',',1)
FROM `dump`)
我希望将它们全部插入到另一个表的一个列中,所以我试图将不合并它们放在一起,而不是每个都会进入一个新行,所以我试着做的是:
INSERT INTO cuisines(name) VALUES (
(SELECT
substring_index(`Cuisines`,',',1),
substring_index(substring_index(`Cuisines`,',',-7),',',1),
substring_index(substring_index(`Cuisines`,',',-6),',',1),
substring_index(substring_index(`Cuisines`,',',-5),',',1),
substring_index(substring_index(`Cuisines`,',',-4),',',1),
substring_index(substring_index(`Cuisines`,',',-3),',',1),
substring_index(substring_index(`Cuisines`,',',-2),',',1),
substring_index(substring_index(`Cuisines`,',',-1),',',1)
FROM `dump`))
有没有办法单独在MySQL上做到这一点?
答案 0 :(得分:0)
INSERT INTO cuisines(name)
VALUES ((SELECT substring_index(`Cuisines`,',',1) FROM `dump`));
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-7),',',1)FROM `dump`))
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-6),',',1)FROM `dump`))
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-5),',',1)FROM `dump`))
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-4),',',1)FROM `dump`))
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-3),',',1)FROM `dump`))
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-2),',',1)FROM `dump`))
INSERT INTO cuisines(name) VALUES (
(SELECT substring_index(substring_index(`Cuisines`,',',-1),',',1) FROM `dump`))