sql leetcode 627. Swap Salary
来源:互联网 发布:playclub捏脸数据论坛 编辑:程序博客网 时间:2024/05/16 17:37
leetcode现在居然加入了sql题,真是涵盖万千啊。
Given a table salary
, such as the one below, that has m=male and f=female values. Swap all f and m values (i.e., change all f values to m and vice versa) with a single update query and no intermediate temp table.
| id | name | sex | salary ||----|------|-----|--------|| 1 | A | m | 2500 || 2 | B | f | 1500 || 3 | C | m | 5500 || 4 | D | f | 500 |After running your query, the above salary table should have the following rows:
| id | name | sex | salary ||----|------|-----|--------|| 1 | A | f | 2500 || 2 | B | m | 1500 || 3 | C | f | 5500 || 4 | D | m | 500 |解法有2种。
第一种:使用条件语句:
UPDATE salary SET sex = (CASE WHEN sex = 'm' THEN 'f' ELSE 'm' END)或者
UPDATE salary SET sex = IF(sex = 'm', 'f', 'm')
update salary set sex = CHAR(ASCII('f') ^ ASCII('m') ^ ASCII(sex));
阅读全文
0 0
- sql leetcode 627. Swap Salary
- [leetcode]627. Swap Salary
- 【LeetCode】627. Swap Salary
- 【leetcode】627. Swap Salary
- LeetCode-627. Swap Salary
- [LeetCode] 627.Swap Salary
- LeetCode——627. Swap Salary(数据库,sql)
- 【LeetCode】627、Swap Salary
- 627. Swap Salary
- 627. Swap Salary
- 627. Swap Salary
- 627. Swap Salary
- 627.SWAP Salary
- LC 627. Swap Salary
- 【leetcode SQL】Second Highest Salary
- 627. Swap Salary--UPDATE and CASE...WHEN
- [LeetCode] Department Highest & Top 3 Salary - SQL
- leetcode SQL题目 177. Nth Highest Salary
- RecyclerView使用介绍
- 解决hostsplus无法安装的问题
- mosquitto的鉴权配置
- Linux下搭建Jenkins+Github环境
- 微软之意不在Xbox,而在于将VR AR引入Win 10
- sql leetcode 627. Swap Salary
- 进程和线程
- Android商城购物车页面实现和逻辑实现
- HDU1595 find the longest of the shortest(dijk+路径记录+枚举)
- 记录一下Struts学习过程中遇到的问题
- Android Studio报错Error:Server sent an unsupported extension: type_35/下载依赖失败/gradle resolve dependenci
- 从网络获取数据,并绑定到listview上
- java eclipse的左侧目录栏不见了
- iOS基石 —— 不常用的基础控件