当前位置:网站首页>627. Change of gender
627. Change of gender
2022-08-05 02:33:00 【just six 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));
边栏推荐
- C学生管理系统 据学号查找学生节点
- 协作D2D局部模型聚合的半分散联合学习
- STM32使用stm32cubemx LL库系列教程
- VSCode Change Default Terminal how to modify the Default Terminal VSCode
- std::string::find 返回值的坑
- 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
- 转:查尔斯·汉迪:你是谁,比你做什么更重要
- 数据增强Mixup原理与代码解读
- C student management system head to add a student node
- nodeJs--封装路由
猜你喜欢

01 【前言 基础使用 核心概念】

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

如何逐步执行数据风险评估
![[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?](/img/81/2dcb61fd6c30f726804c73cf2b3384.jpg)
[Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?

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

树表的查找

VSCode Change Default Terminal 如何修改vscode的默认terminal

The 20th day of the special assault version of the sword offer

sql语句多字段多个值如何进行排序

Go 微服务开发框架 DMicro 的设计思路
随机推荐
后期学习计划
1527. 患某种疾病的患者
".NET IoT from scratch" series
继承关系下构造方法的访问特点
js中try...catch和finally的用法
继承关系下构造方法的访问特点
Domain Driven Design - MDD
J9数字货币论:web3的创作者经济是什么?
Greenplum Database Fault Analysis - Why Does gpstart -a Return Failure After Version Upgrade?
RAID disk array
mysql tree structure query problem
Hypervisor related knowledge points
SDC简介
Common hardware delays
select tag custom style
SuperMap支持的国产环境汇总
lua学习
leetcode-另一棵树的子树
【日常训练】1403. 非递增顺序的最小子序列
线性表的查找