
update salary set
sex = (case sex
when ‘m’ then ‘f’
else ‘m’
end);
或
update salary set sex=if(sex = ‘f’, ‘m’,‘f’);
参考:https://leetcode-cn.com/problems/swap-salary/solution/tu-jie-sqlmian-shi-ti-ru-he-an-tiao-jian-xiu-gai-s/
本文介绍了如何使用SQL语句更新数据库中性别字段的值,通过条件判断实现性别信息的互换,提供了两种实现方法,包括CASE WHEN语句和IF函数的应用。

update salary set
sex = (case sex
when ‘m’ then ‘f’
else ‘m’
end);
或
update salary set sex=if(sex = ‘f’, ‘m’,‘f’);
参考:https://leetcode-cn.com/problems/swap-salary/solution/tu-jie-sqlmian-shi-ti-ru-he-an-tiao-jian-xiu-gai-s/
7504
1342

被折叠的 条评论
为什么被折叠?