当前位置:网站首页>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));
边栏推荐
- The 20th day of the special assault version of the sword offer
- 采用redis缓存的linux主从同步服务器图片硬盘满了移到新目录要修改哪些指向
- 02 [Development Server Resource Module]
- 网络安全与元宇宙:找出薄弱环节
- 【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?
- 短域名绕过及xss相关知识
- 树形查找(二叉查找树)
- 散列表的查找(哈希表)
- C student management system Find student nodes based on student ID
- 学习笔记-----左偏树
猜你喜欢

select 标签自定义样式

甘特图来啦,项目管理神器,模板直接用

nodeJs--封装路由

Jincang database KingbaseES V8 GIS data migration solution (3. Data migration based on ArcGIS platform to KES)

Flink 1.15.1 集群搭建(StandaloneSession)

Hypervisor related knowledge points

2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!

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

nodeJs--encapsulate routing
![02 [Development Server Resource Module]](/img/60/f77ed0bb0e5654c9dcd70b73a5bee8.png)
02 [Development Server Resource Module]
随机推荐
[Fortune-telling-60]: "The Soldier, the Tricky Way"-2-Interpretation of Sun Tzu's Art of War
Understand the recommendation system in one article: Recall 06: Two-tower model - model structure, training method, the recall model is a late fusion feature, and the sorting model is an early fusion
Error: Not a signal or slot declaration
02 【开发服务器 资源模块】
基于左序遍历的数据存储实践
select 标签自定义样式
SuperMap支持的国产环境汇总
用@Mapper查询oracle的分区情况报错
从零到一快速学会三子棋
leetcode-另一棵树的子树
C student management system Find student nodes based on student ID
常见的硬件延迟
力扣-二叉树的前序遍历、中序遍历、后序遍历
How to deal with your own shame
View handler 踩坑记录
iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?
Apache DolphinScheduler新一代分布式工作流任务调度平台实战-中
Error: Not a signal or slot declaration
【存储】曙光存储DS800-G35 ISCSI各映射LUN给服务器
Unleashing the engine of technological innovation, Intel joins hands with ecological partners to promote the vigorous development of smart retail