Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql sql查询将表中的城市浦那替换为孟买,孟买替换为浦那_Mysql_Sql - Fatal编程技术网

Mysql sql查询将表中的城市浦那替换为孟买,孟买替换为浦那

Mysql sql查询将表中的城市浦那替换为孟买,孟买替换为浦那,mysql,sql,Mysql,Sql,我有一个列名为city的表emp city output table ----- mumbai pune pune mumbai mumbai pune pune mumbai pune

我有一个列名为city的表emp

city                         output table
-----
mumbai                           pune
pune                             mumbai
mumbai                           pune
pune                             mumbai
pune                             mumbai

我希望更新查询以替换pune到孟买和mumbai到pune

您可以通过查询执行此操作:

select (case when city = 'mumbai' then 'pune'
             when city = 'pune' then 'mumbai'
             else city
        end)
. . .
如果要更改值,请执行以下操作:

update table t
     set city = (case when city = 'mumbai' then 'pune'
                      when city = 'pune' then 'mumbai'
                 end)
     where city in ('mumbai', 'pune');
请尝试以下方法:

UPDATE TABLENAME
SET city= (
CASE 

WHEN city = 'mumbai'
THEN 'pune'

WHEN city = 'pune'
THEN 'mumbai'

END )
希望能有帮助