我有一个包含名称empdetail
和列的表:
Id Name Gender
1 ABC Male
2 XYZ Female
3 PQR Male
我想通过单个查询Gender
将每个 emp 从Male
toFemale
和 from Female
to更改为Male
结果应该是这样的:
1 ABC Female
2 XYZ Male
3 PQR Female
我有一个包含名称empdetail
和列的表:
Id Name Gender
1 ABC Male
2 XYZ Female
3 PQR Male
我想通过单个查询Gender
将每个 emp 从Male
toFemale
和 from Female
to更改为Male
结果应该是这样的:
1 ABC Female
2 XYZ Male
3 PQR Female
您只需要使用CASE语句
update <table>
set Gender= case when Gender='Male' then 'Female'
when Gender='Female' then 'Male'
end
select id,name,
(case when gender='Male'
then 'Female'
else 'Male'
end) as 'Gender'
from table
-------------------
update table set gender=(case when gender='Male'
then 'Female' else 'Male' end)