当前位置:网站首页>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));
边栏推荐
- Domain Driven Design - MDD
- C语言日记 9 if的3种语句
- [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
- SuperMap iDesktop.Net之布尔运算求交——修复含拓扑错误复杂模型
- HOG feature study notes
- 多线程(2)
- The 2022 EdgeX China Challenge will be grandly opened on August 3
- VSCode Change Default Terminal 如何修改vscode的默认terminal
- SuperMap支持的国产环境汇总
- 【MySQL series】- Does LIKE query start with % will make the index invalid?
猜你喜欢

RAID disk array

J9数字货币论:web3的创作者经济是什么?

lua学习

lua learning

常见的硬件延迟

How do programmers without objects spend the Chinese Valentine's Day

【LeetCode刷题】-数之和专题(待补充更多题目)

Hypervisor related knowledge points

The 2022 EdgeX China Challenge will be grandly opened on August 3

2022-08-04: Input: deduplicated array arr, the numbers in it only contain 0~9.limit, a number.Return: The maximum number that can be spelled out with arr if the requirement is smaller than limit.from
随机推荐
select 标签自定义样式
采用redis缓存的linux主从同步服务器图片硬盘满了移到新目录要修改哪些指向
lua learning
Regular expression to match a certain string in the middle
leetcode-对称二叉树
Fragment visibility judgment
QT语言文件制作
Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
转:查尔斯·汉迪:你是谁,比你做什么更重要
C学生管理系统 指定位置插入学生节点
【LeetCode刷题】-数之和专题(待补充更多题目)
Using OpenVINO to implement the flying paddle version of the PGNet inference program
Flink 1.15.1 集群搭建(StandaloneSession)
nodeJs--封装路由
VSCode Change Default Terminal 如何修改vscode的默认terminal
[ROS](10)ROS通信 —— 服务(Service)通信
ARM Mailbox
post-study program
How to simply implement the quantization and compression of the model based on the OpenVINO POT tool
Domain Driven Design - MDD