0

我有一张桌子叫汉堡包。我想清理数据并从汉堡包名称周围删除一些垃圾文本,并且只在标题字段中使用汉堡包的名称。到目前为止,这就是我的小脑袋所能鼓起的全部......

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。

4

1 回答 1

1

这可能会让你朝着正确的方向前进:

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 %,";

不过,它确实有点依赖于汉堡包后面有一个逗号....

于 2013-03-01T15:32:57.020 回答