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

Optimizing the feed flow encountered obstacles, who helped Baidu break the "memory wall"?

编译预处理等细节

Common hardware delays

Pisanix v0.2.0 released | Added support for dynamic read-write separation

云原生(三十二) | Kubernetes篇之平台存储系统介绍

matlab绘制用颜色表示模值大小的箭头图

Simple implementation of YOLOv7 pre-training model deployment based on OpenVINO toolkit

Pisanix v0.2.0 发布|新增动态读写分离支持

基于左序遍历的数据存储实践

01 【前言 基础使用 核心概念】
随机推荐
C语言实现简单猜数字游戏
【日常训练】1403. 非递增顺序的最小子序列
QT语言文件制作
2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!
DAY23: Command Execution & Code Execution Vulnerability
Tree search (bintree)
1484. 按日期分组销售产品
C student management system head to add a student node
短域名绕过及xss相关知识
C语言日记 9 if的3种语句
Matlab画图3
使用SuperMap iDesktopX数据迁移工具迁移地图文档和符号
[ROS] (10) ROS Communication - Service Communication
hypervisor相关的知识点
浅谈数据安全治理与隐私计算
【genius_platform软件平台开发】第七十六讲:vs预处理器定义的牛逼写法!!!!(其他组牛逼conding人员告知这么配置来取消宏定义)
如何模拟后台API调用场景,很细!
Greenplum数据库故障分析——能对数据库base文件夹进行软连接嘛?
nodeJs--encapsulate routing
Opening - Open a new .NET modern application development experience