当前位置:网站首页>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));
边栏推荐
- Matlab画图3
- 线性表的查找
- [Decryption] Can the NFTs created by OpenSea for free appear in my wallet without being chained?
- DAY23: Command Execution & Code Execution Vulnerability
- Common hardware delays
- Introduction to SDC
- 在这个超连接的世界里,你的数据安全吗
- 使用SuperMap iDesktopX数据迁移工具迁移ArcGIS数据
- Pisanix v0.2.0 released | Added support for dynamic read-write separation
- J9数字货币论:web3的创作者经济是什么?
猜你喜欢
DAY22:sqli-labs 靶场通关wp(Less01~~Less20)
02 [Development Server Resource Module]
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
【OpenCV 图像处理2】:OpenCV 基础知识
虚拟内存原理与技术
OpenGL 工作原理
树表的查找
shell语句修改txt文件或者sh文件
leetcode 15
C language implements a simple number guessing game
随机推荐
Compressed storage of special matrices
Dotnet 6 Why does the network request not follow the change of the system network proxy and dynamically switch the proxy?
select 标签自定义样式
Advanced Numbers_Review_Chapter 1: Functions, Limits, Continuity
Fragment visibility judgment
程序员的七夕浪漫时刻
浅谈数据安全治理与隐私计算
HDU 1114:Piggy-Bank ← 完全背包问题
C学生管理系统 据学号查找学生节点
数据增强Mixup原理与代码解读
VSCode Change Default Terminal how to modify the Default Terminal VSCode
C student management system Find student nodes based on student ID
LeetCode使用最小花费爬楼梯----dp问题
开源协议说明LGPL
OpenGL 工作原理
nodeJs--封装路由
继承关系下构造方法的访问特点
nodeJs--encapsulate routing
leetcode 15
【日常训练】1403. 非递增顺序的最小子序列