我有一张名为汉堡包的 table 。我想清理数据并删除汉堡包名称周围的一些垃圾文本,并且仅在标题字段中使用汉堡包的名称。到目前为止,这是我的小脑袋所能聚集的一切......
UPDATE hamburgers
SET title = SELECT SUBSTRING_INDEX(title, "My favorite hamburger is called %, I'm not really sure why. Yesterday was the first time I ate a %", -1) FROM hamburgers
where title like "%My favorite hamburger is called %.%";
我对 MySql 很烂,但我只想找到一种方法来删除汉堡名称周围的文本。大约有 3,000 条记录的汉堡名称周围有完全相同的文本。 TIA。
最佳答案
这可能会让您朝着正确的方向前进:
select substring_index(substring_index("My favorite hamburger is called Whopper, I'm not really sure why. Yesterday was the first time I ate a Whopper","My favorite hamburger is called ",-1),",",1);
这将为您提供:
Whopper
所以:
UPDATE hamburgers
SET title = substring_index(substring_index(title,"My favorite hamburger is called ",-1),",",1)
where title like "My favorite hamburger is called %,";
它确实有点依赖于汉堡包后面有一个逗号......
关于mysql 使用带有通配符的 substring_index 从字段中删除不需要的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15161124/