当前位置:网站首页>627. 变更性别
627. 变更性别
2022-08-05 02:32:00 【只是六号z】
前言
Salary 表:
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| id | int |
| name | varchar |
| sex | ENUM |
| salary | int |
+-------------+----------+
id 是这个表的主键。
sex 这一列的值是 ENUM 类型,只能从 ('m', 'f') 中取。
本表包含公司雇员的信息。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/swap-salary
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
请你编写一个 SQL 查询来交换所有的 ‘f’ 和 ‘m’ (即,将所有 ‘f’ 变为 ‘m’ ,反之亦然),仅使用 单个 update 语句 ,且不产生中间临时表。
注意,你必须仅使用一条 update 语句,且 不能 使用 select 语句。
查询结果如下例所示。
示例1:
输入:
Salary 表:
+----+------+-----+--------+
| id | name | sex | salary |
+----+------+-----+--------+
| 1 | A | m | 2500 |
| 2 | B | f | 1500 |
| 3 | C | m | 5500 |
| 4 | D | f | 500 |
+----+------+-----+--------+
输出:
+----+------+-----+--------+
| id | name | sex | salary |
+----+------+-----+--------+
| 1 | A | f | 2500 |
| 2 | B | m | 1500 |
| 3 | C | f | 5500 |
| 4 | D | m | 500 |
+----+------+-----+--------+
解释:
(1, A) 和 (3, C) 从 'm' 变为 'f' 。
(2, B) 和 (4, D) 从 'f' 变为 'm' 。
来源:力扣(LeetCode)
链接:https://leetcode.cn/problems/swap-salary
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
1、if
update salary set sex = if(sex = 'm','f','m');
2、case + when + else
update salary
set sex = (
case sex when 'm' then 'f' else 'm' end
) ;
3、char + ascii
update salary set sex = char(ascii('m') + ascii('f') - ascii(sex));
边栏推荐
- std::string::find 返回值的坑
- 如何模拟后台API调用场景,很细!
- Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?
- [ROS](10)ROS通信 —— 服务(Service)通信
- 用@Mapper查询oracle的分区情况报错
- SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
- Fragment visibility judgment
- nodeJs--encapsulate routing
- [In-depth study of 4G/5G/6G topic-51]: URLLC-16-"3GPP URLLC related protocols, specifications, and technical principles in-depth interpretation"-11-High reliability technology-2-Link adaptive enhancem
- 浅谈数据安全治理与隐私计算
猜你喜欢

Access Characteristics of Constructor under Inheritance Relationship

Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
![[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)](/img/ee/6b52072c841af99488dc0c1141c74c.png)
[LeetCode Brush Questions] - Sum of Numbers topic (more topics to be added)

浅谈数据安全治理与隐私计算

nodeJs--封装路由

C语言日记 9 if的3种语句
![[ROS] (10) ROS Communication - Service Communication](/img/4d/4657f24bd7809abb4bdc4b418076f7.png)
[ROS] (10) ROS Communication - Service Communication

没有对象的程序员如何过七夕

js中try...catch和finally的用法

【 2 】 OpenCV image processing: basic knowledge of OpenCV
随机推荐
[深入研究4G/5G/6G专题-51]: URLLC-16-《3GPP URLLC相关协议、规范、技术原理深度解读》-11-高可靠性技术-2-链路自适应增强(根据无线链路状态动态选择高可靠性MCS)
Common hardware delays
【MySQL系列】- LIKE查询 以%开头一定会让索引失效吗
Intel XDC 2022 Wonderful Review: Build an Open Ecosystem and Unleash the Potential of "Infrastructure"
shell statement to modify txt file or sh file
2022-08-04:输入:去重数组arr,里面的数只包含0~9。limit,一个数字。 返回:要求比limit小的情况下,能够用arr拼出来的最大数字。 来自字节。
"Dilili, wait for the lights, wait for the lights", the prompt sound for safe production in the factory
散列表的查找(哈希表)
mysql tree structure query problem
【 2 】 OpenCV image processing: basic knowledge of OpenCV
程序员的七夕浪漫时刻
iNFTnews | What can NFTs bring to the sports industry and fans?
Solve connect: The requested address is not valid in its context
Images using redis cache Linux master-slave synchronization server hard drive full of moved to the new directory which points to be modified
意识形态的机制
matlab绘制用颜色表示模值大小的箭头图
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
nodeJs--封装路由
DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
Opening - Open a new .NET modern application development experience