选择后替换行中的所有值

时间:2016-10-29 20:10:59

标签: mysql

我正在尝试在phpMyAdmin中执行MySQL命令,以便在从其他列特定值中选择某些值后,我可以替换列中的所有值。

我用来选择它们的查询是:

SELECT * FROM `homes` WHERE `world` LIKE '%plot%'

但是,我试图在选择所有值后替换列中的所有值:

SELECT world,server, REPLACE(server,'drug','plots') FROM homes WHERE world='%plot%'

我不完全确定我需要做什么,但这里有一张图片可以解释一下。

enter image description here

我也尝试了这些查询,但没有任何运气:

update homes set server = "plots" where world = '%plot%';
SELECT world,server, REPLACE(server,'drug','plots') FROM homes WHERE world='%plot%'

1 个答案:

答案 0 :(得分:0)

我不确定我是否理解你的问题,但你的意思是这样吗?

SELECT  world
,       server
,       case server 
          when 'drug' then 'differentValue'
          when 'med' then 'anotherdifferentValue'
        end server2  
FROM homes 
WHERE world like 'plot%'