0
Table

ID    DESC
1     Male
2     Male
3     Male
4     Female
5     Female
6     Female
7     Female

我需要使用一个更新语句将男性更新为女性,将女性更新为男性。请就此提出建议。提前致谢。

4

3 回答 3

2

尝试这个

UPDATE Table
SET DESC  = CASE 
    WHEN DESC= 'Male' THEN 'Female'
    WHEN DESC  = 'Female' THEN 'Male'
    ELSE DESC        
  END 

输出如下

ID    DESC

1     Female
2     Female
3     Female
4     Male
5     Male
6     Male
7     Male
于 2013-04-25T11:33:43.927 回答
0

是的,您可以使用case语句来做到这一点

UPDATE TABLE
SET DESC = CASE WHEN DESC = 'MALE' THEN 'Female' WHEN DESC = 'Female' THEN 'MALE' ELSE DESC END
于 2013-04-25T11:17:28.457 回答
0

对于 SQL 服务器

update tbl
SET DESC  = CASE 
    WHEN DESC= 'Male' THEN 'Female'
    WHEN DESC  = 'Female' THEN 'Male'
    ELSE DESC        
  END 
于 2013-04-25T11:16:14.813 回答