1

我有一个包含名称empdetail和列的表:

   Id  Name  Gender
    1  ABC   Male
    2  XYZ   Female
    3  PQR   Male

我想通过单个查询Gender将每个 emp 从MaletoFemale和 from Femaleto更改为Male

结果应该是这样的:

1 ABC Female
2 XYZ Male
3 PQR Female
4

2 回答 2

4

您只需要使用CASE语句

update <table>
set Gender= case when Gender='Male' then 'Female' 
                 when Gender='Female' then 'Male' 
            end


SQL小提琴演示

于 2012-10-11T06:13:03.607 回答
0
    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) 
于 2012-10-11T06:11:07.587 回答