如何使用同一查询编辑 mysql 中的多个不同行

How to edit multiple distinct rows in mysql with the same query

我有一个 mysql table,其中一行包含词汇,如下所示:

还有一个独特的列。问题是并不是所有的动词都像上面那样在不定式中使用 to,所以实际上 table 看起来更像这样:

是否可以在没有 to 的情况下编辑所有这些行,以便他们拥有它,我。 e.所以第二个例子看起来像上面的第一个?否则我将不得不完成整个过程并手动编辑它们,这非常耗时。

一目了然:

SELECT * FROM vocab where french not like "to %";

但编辑它们?

当然,使用更新:

UPDATE vocab 
SET french = CONCAT("to ", french)
where french not like "to %";

我认为你需要更新:

update vocabulary
set french = 
  concat(substring_index(french, ' ', 1), ' to ', substring_index(french, ' ', -1))
where french not like '% to %'; 

参见demo
结果:

| french              |
| ------------------- |
| aller to go         |
| manger to eat       |
| soulager to relieve |