假设我们有像PEOPLE一样的表格
id | name | extracted
-----------------------------------------
1 | Roger |
-----------------------------------------
2 | Anthony |
-----------------------------------------
3 | Maria |
-----------------------------------------
我们使用
SELECT SUBSTRING(name, 1, 3) FROM people.name WHERE name like '%thon%'
它会找到“安东尼”并提取3个第一个字符 - 所以结果是: 蚂蚁
如何将此结果设置为相同的ID,以使表格看起来像
id | name | extracted
-----------------------------------------
1 | Roger |
-----------------------------------------
2 | Anthony | Ant
-----------------------------------------
3 | Maria |
-----------------------------------------
答案 0 :(得分:2)
尝试
UPDATE people SET extracted = LEFT(`name`,3) WHERE `name` like '%thon%'