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.

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 |
# Write your MySQL query statement below
update salary set sex= case sex when 'f' then 'm' else 'f' end

LeetCode - 627. Swap Salary的更多相关文章

  1. leetcode 627. Swap Salary 数据库带判断的更新操作

    https://leetcode.com/problems/swap-salary/description/ 用  set keyWord = Case depentedWord when haha ...

  2. LeetCode 627. Swap Salary (交换工资)

    题目标签: 题目给了我们一个 工资表格,让我们把 男女性别对换. 这里可以利用IF, IF(condition, value_if_true, value_if_false). Java Soluti ...

  3. 627. Swap Salary

    627. Swap Salary SQL Schema Given a table salary, such as the one below, that has m=male and f=femal ...

  4. [LeetCode] 627. Swap Salary_Easy tag: SQL

    Given a table salary, such as the one below, that has m=male and f=female values. Swap all f and m v ...

  5. SQL语句中IF的简单使用 - 关联leetcode 627.交换工资

    MySQL的IF既可以作为表达式用,也可在存储过程中作为流程控制语句使用,如下是做为表达式使用: IF表达式 IF(expr1,expr2,expr3) 如果 expr1 是TRUE (expr1 & ...

  6. [SQL]LeetCode627. 交换工资 | Swap Salary

    SQL架构 create table ), sex ), salary int) Truncate table salary insert into salary (id, name, sex, sa ...

  7. [LeetCode] Department Highest Salary 系里最高薪水

    The Employee table holds all employees. Every employee has an Id, a salary, and there is also a colu ...

  8. [LeetCode] Nth Highest Salary 第N高薪水

    Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...

  9. [LeetCode] Second Highest Salary 第二高薪水

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

随机推荐

  1. TP框架自带的正则验证的规则

    thinkphp框架里面自带有很多自动验证的规则,下面是框架自带的正则验证的规则,官方的说明文档里面没有这么多,所以记下来,以备使用. view sourceprint? 01 static $reg ...

  2. JavaSE笔记-泛型

    定义带泛型的类 public class Cat<T> { //可以用T定义实例变量 private T name; //可以用T定义形参 //构造器没有<> public C ...

  3. 邓_tp_笔记

    <?phpnamespace app\teacher\controller;use think\Db;use app\common\model\Classcourse;use app\commo ...

  4. libpng+VS2012(VS2015)的使用

    OpenCV保存PNG图像底层调用的就是libpng库,简要说一下libPNG库的单独使用. 1.首先需要下载两个库,一个是libpng,一个是zlib libpng库下载地址:http://www. ...

  5. C# winform页面可视化设计打开失败,提示未能加载程序集或他的一个依赖项,dll错误

    这种情况发生在最初项目是x86属性,改成x64后,一些原来dll,页面没有及时更新,导致页面找不到dll, 最简单的解决方式,把项目属性改成AnyCpu,重新编译下,就可以打开可视化设计窗口了.

  6. 2017-07-11(sync basename dirname )

    sync 在内存中尚未被更新的数据,就会被写入硬盘中:在关机或者重启前,最好多执行几次! basename 获取文件名 dirname 获取目录名

  7. Spring注解装配

    Spring 自动装配的主机有 @Autowired.@Intect.@Resource @Autowired是byType的, @Resource是byName的.我们一般用@Atutowired. ...

  8. xen虚拟机(Centos6.6)的创建和扩容

    好久没来更博了,从这篇开始,我准备好好梳理一下Hadoop的那些"事".本人技术渣一枚,只是本着知识共享的原则,希望将我所掌握的知识分享出来.若文中有错误的地方,欢迎大家告知我,我 ...

  9. 一种CListCtrl自绘效果

  10. Linux指令--rm, rmdir

    rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所有文件及子目录均删除.对于链接文件,只是删除了链接,原有文件均保持不变.rm是一个危险的命令,使用的时 ...