2013-03-01 60 views
0

我有一個名爲hamburgers的表。我想清理數據並從漢堡名稱周圍刪除一些垃圾文本,只在標題字段中使用漢堡包的名稱。到目前爲止,這是我的小腦袋可以鼓起...mysql使用substring_index和通配符從字段中刪除不需要的文本

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,但我只是想找出一種方法來去除環境漢堡包的名稱的文本。有三千條左右​​的記錄與漢堡包的名稱相同。 TIA。

回答

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

它有點依賴於有是一個漢堡之後的逗號雖然....

相關問題