[LeetCode] 627. Swap Salary_Easy tag: SQL
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.
For example:
| 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 |
Code
UPDATE Salary SET sex = IF(sex = 'f', 'm', 'f')
也就是说if sex == 'f' , sex = 'm'
else: sex = 'f'
[LeetCode] 627. Swap Salary_Easy tag: SQL的更多相关文章
- [LeetCode] 176. Second Highest Salary_Easy tag: SQL
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- LeetCode - 627. Swap Salary
Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m v ...
- [LeetCode] 182. Duplicate Emails_Easy tag: SQL
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- [LeetCode] 197. Rising Temperature_Easy tag: SQL
Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to ...
- [LeetCode] 595. Big Countries_Easy tag: SQL
There is a table World +-----------------+------------+------------+--------------+---------------+ ...
- leetcode 627. Swap Salary 数据库带判断的更新操作
https://leetcode.com/problems/swap-salary/description/ 用 set keyWord = Case depentedWord when haha ...
- LeetCode 627. Swap Salary (交换工资)
题目标签: 题目给了我们一个 工资表格,让我们把 男女性别对换. 这里可以利用IF, IF(condition, value_if_true, value_if_false). Java Soluti ...
- [LeetCode] 610. Triangle Judgement_Easy tag: SQL
A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. Ho ...
- [LeetCode] 607. Sales Person_Easy tag: SQL
Description Given three tables: salesperson, company, orders.Output all the names in the table sales ...
随机推荐
- 线程同步之ManualResetEvent类的用法
笔者的一台激光测厚设备的软件, 它有一个运动线程, 一个激光数据处理线程. 运动线程做的事就是由A点移动到B点, 然后再由B点移动回A点. 激光处理线程要做的事就是采集指定数量点的激光数据, 随着采集 ...
- android 线程间的通信
(转自:http://www.cnblogs.com/allin/archive/2010/05/19/1738800.html) andriod提供了 Handler 和 Looper 来满足线程间 ...
- jenkins部署war包到远程服务器的tomcat
一.目的 jenkins上将war包,部署到远程服务器的tomcat上. 这边tomcat在windows 主机A上,版本apache-tomcat-8.5.23. jenkins在主机B上,cent ...
- 打开指定目录路径的CMD命令行窗口
1.打开目录文件夹, Shift + 右键 2.会直接打开CMD所在的目录路径
- Tomcat应用的部署记录
1.先安装jdk,解压jdk-7u17-linux-x64.tar.gz至/opt目录.配置环境变量,在/etc/profile末加入如下内容. JAVA_HOME=/opt/jdk1..0_17 e ...
- lombok 转载
http://www.blogjava.net/fancydeepin/archive/2012/07/12/lombok.html LomBok主要特性有:自动生成默认的getter/setter方 ...
- GPU对数据的操作不可累加
我想当然的认为GPU处理数据时可以共同访问内存,所以对数据的操作是累加的. 事实证明:虽然GPU多个核可以访问同一块内存,但彼此之间没有依赖关系,它们对这块内存的作用无法累加. 先看代码: #incl ...
- git--指定不上传的文件夹
在使用 vue-cli 脚手架的时候,有一个依赖模板文件夹是不希望被上传到git上的,因为里面文件太多了. 解决办法:手动创建git忽略push清单,node_module以及自身 1.文件夹内右键g ...
- ArchLinux 添加国内镜像源
$ vim /etc/pacman.d/mirrorlist # 在最前面添加一行,这样就成功添加了网易的源: Server = http://mirrors.163.com/archlinux/$r ...
- html的base标签
提示:请把 <base> 标签排在 <head> 元素中第一个元素的位置,这样 head 区域中其他元素就可以使用 <base> 元素中的信息了. 注释:如果使用了 ...