当前位置:网站首页>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));
边栏推荐
猜你喜欢

iNFTnews | 对体育行业和球迷来说,NFT可以带来什么?

LeetCode uses the minimum cost to climb the stairs----dp problem

【MySQL series】- Does LIKE query start with % will make the index invalid?
![[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)

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

Gantt chart is here, project management artifact, template is used directly

【解密】OpenSea免费创造的NFT都没上链竟能出现在我的钱包里?

leetcode 15

Go 微服务开发框架 DMicro 的设计思路

Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?
随机推荐
Access Characteristics of Constructor under Inheritance Relationship
Introduction to SDC
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
Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit
01 【前言 基础使用 核心概念】
Unleashing the engine of technological innovation, Intel joins hands with ecological partners to promote the vigorous development of smart retail
Images using redis cache Linux master-slave synchronization server hard drive full of moved to the new directory which points to be modified
.Net C# 控制台 使用 Win32 API 创建一个窗口
散列表的查找(哈希表)
2022-08-04:输入:去重数组arr,里面的数只包含0~9。limit,一个数字。 返回:要求比limit小的情况下,能够用arr拼出来的最大数字。 来自字节。
正则表达式,匹配中间的某一段字符串
std::string::find 返回值的坑
线上MySQL的自增id用尽怎么办?
Using OpenVINO to implement the flying paddle version of the PGNet inference program
Solve connect: The requested address is not valid in its context
sql语句多字段多个值如何进行排序
KingbaseES V8 GIS data migration solution (2. Introduction to the capabilities of Kingbase GIS)
C student management system Find student nodes based on student ID
DAY22: sqli-labs shooting range clearance wp (Less01~~Less20)
lua learning