MySQL在不同的字段中搜索和替换

时间:2022-12-27 19:21:45

Hi I imported a bunch of driving games to my arcade website but only some land in the "Driving" category. some land in the action and adventure category be accident. I need to fix this in phpMyAdmin mysql terminal. My code is trying to search the database for keywords in my tags field and replace the entity's category from Action or whatever it might be to Driving

嗨我把一堆驾驶游戏导入我的街机网站,但只有一些在“驾驶”类别。行动和冒险类别中的一些土地是意外的。我需要在phpMyAdmin mysql终端中解决这个问题。我的代码试图在我的标签字段中搜索数据库中的关键字,并将实体的类别从Action或其他任何内容替换为Driving

Here is my code, but is does not seem to work

这是我的代码,但似乎不起作用

SELECT * FROM games WHERE tags LIKE '%truck%'
UPDATE games SET category = replace (category, "%", "Driving")
SELECT * FROM games WHERE tags LIKE '%car%'
UPDATE games SET category = replace (category, "%", "Driving")
SELECT * FROM games WHERE tags LIKE '%drive%'
UPDATE games SET category = replace (category, "%", "Driving")
SELECT * FROM games WHERE tags LIKE '%race%'
UPDATE games SET category = replace (category, "%", "Driving")

1 个解决方案

#1


0  

Find records with tags column containing truck or car or drive or race.

查找包含卡车或汽车或驾驶或比赛的标签列的记录。

Update mytable
SET category = 'Driving'
where tags REGEXP 'truck|car|drive|race'
;

another:

Update mytable
SET category = 'Driving'
where tags LIKE '%truck%' 
OR LIKE '%car%' OR LIKE '%drive%' OR LIKE '%race%' 
;

#1


0  

Find records with tags column containing truck or car or drive or race.

查找包含卡车或汽车或驾驶或比赛的标签列的记录。

Update mytable
SET category = 'Driving'
where tags REGEXP 'truck|car|drive|race'
;

another:

Update mytable
SET category = 'Driving'
where tags LIKE '%truck%' 
OR LIKE '%car%' OR LIKE '%drive%' OR LIKE '%race%' 
;