当前位置:网站首页>[SQL simple question] leetcode 627. change gender
[SQL simple question] leetcode 627. change gender
2022-07-27 03:04:00 【Wow, Kaka, negative, positive】
LeetCode 627. Changing gender
https://leetcode.cn/problems/swap-salary/
Please write a SQL Query to exchange all 'f' and 'm' ( namely , Will all 'f' Turn into 'm' , vice versa ), Use only Single update sentence , And there is no intermediate temporary table .
Be careful , You must use only one update sentence , And You can't Use select sentence .
Input :
Salary surface :
+----+------+-----+--------+
| id | name | sex | salary |
+----+------+-----+--------+
| 1 | A | m | 2500 |
| 2 | B | f | 1500 |
| 3 | C | m | 5500 |
| 4 | D | f | 500 |
+----+------+-----+--------+
Output :
+----+------+-----+--------+
| id | name | sex | salary |
+----+------+-----+--------+
| 1 | A | f | 2500 |
| 2 | B | m | 1500 |
| 3 | C | f | 5500 |
| 4 | D | m | 500 |
+----+------+-----+--------+
Solution
Addition and subtraction
UPDATE Salary SET sex = char(ascii('m') + ascii('f') - ascii(sex));
Exclusive or law
UPDATE Salary SET sex = char(ascii(sex) ^ ascii('m') ^ ascii('f'));
if Function judgment statement
UPDATE Salary SET sex = IF(sex='f', 'm', 'f');
case-when-then-else-end sentence
UPDATE Salary SET
sex =
CASE sex
WHEN 'm' THEN 'f'
WHEN 'f' THEN 'm'
ELSE 'else'
END;
边栏推荐
- idea中常用的快捷键
- OD-Paper【3】:Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks
- ansible系列之:不收集主机信息 gather_facts: False
- Quick sort
- Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice
- 我的爬虫笔记(七) 通过爬虫实现blog访问量+1
- 全网最全的软件测试基础知识整理(新手入门必学)
- Why do people like to rank things
- com.fasterxml.jackson.databind.exc.InvalidDefinitionException
- 测试人需要的数据库知识:MySQL常用语法
猜你喜欢

Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round

If you want to thoroughly optimize the performance, you must first understand the underlying logic~

Database knowledge required by testers: MySQL common syntax

iNFTnews | “流量+体验”白衬e数字时装节引领数字时装新变迁

Okaleido Tiger 7.27日登录Binance NFT,首轮已获不俗成绩

White box test case design (my grandfather can understand it)

Manually build ABP framework from 0 -abp official complete solution and manually build simplified solution practice

次轮Okaleido Tiger即将登录Binance NFT,引发社区热议

小玩一个并行多线程MCU—MC3172

Database read-write separation and database and table segmentation
随机推荐
CS224W fall 1.2 Applications of Graph ML
Okaleido tiger logged into binance NFT on July 27, and has achieved good results in the first round
Inftnews | "traffic + experience" white lining e Digital Fashion Festival leads the new changes of digital fashion
数据资产管理的概念
次轮Okaleido Tiger即将登录Binance NFT,引发社区热议
[nisactf 2022] upper
[Ryu] common problems and solutions in installing Ryu
测试人需要的数据库知识:MySQL常用语法
I heard that you knelt on the interface test during the interview?
我的爬虫笔记(七) 通过爬虫实现blog访问量+1
B-树的应用以及添加和删除操作
如何白嫖最新版BurpSuite Pro
人们为什么热衷于给事物排序
Time module: acquisition and mutual transformation of timestamp, structured time and formatted time
C language program compilation (preprocessing)
go实现导出excel表格
Plato Farm全新玩法,套利ePLATO稳获超高收益
Cs224w fall course - --- 1.1 why graphs?
Static keyword
全网最全的软件测试基础知识整理(新手入门必学)