我有一个表名为emp的列名
city output table
-----
mumbai pune
pune mumbai
mumbai pune
pune mumbai
pune mumbai
我希望更新查询将pune替换为mumbai和mumbai to pune
答案 0 :(得分:1)
您可以使用查询执行此操作:
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');
答案 1 :(得分:1)
尝试以下方法:
UPDATE TABLENAME
SET city= (
CASE
WHEN city = 'mumbai'
THEN 'pune'
WHEN city = 'pune'
THEN 'mumbai'
END )
希望它有所帮助。