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 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 'm' THEN 'f'
ELSE 'm'
END;
# update salary set sex = if(sex='m', 'f', 'm')  这个运行的时间短

627. Swap Salary的更多相关文章

  1. 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 ...

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

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

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

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

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

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

  5. [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 ...

  6. 627.Swap Salary-(LeetCode之Database篇)

    问题描述 给出下面的表,名为salary. id name sex salary 1 A m 2500 2 B f 1500 3 C m 5500 4 D f 500 要求执行一个UPDATE语句,将 ...

  7. 2017/11/3 Leetcode 日记

    2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum ...

  8. All LeetCode Questions List 题目汇总

    All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...

  9. Leetcode中的SQL题目练习(一)

    595. Big Countries https://leetcode.com/problems/big-countries/description/ Description name contine ...

随机推荐

  1. js 树菜单 ztree

    http://www.ztree.me/v3/api.php 官网 api js /** <div id="menuContent" class="menuCont ...

  2. Scrum培训心得体会

    # Scrum培训心得体会 非常荣幸能够参加公司组织的这场为期两天的培训,赛宝的老师讲的非常好.通过这次学习,理解了当前最流行的Scrum开发框架,下面总结了我对Scrum的理解. ## scrum的 ...

  3. PCB标识说明

    VDC (Voltage Direct Current),直流电压 VBAT,电池供电 PWKEY,电源键 RXD,数据接收 TXD,数据发送 Receive Data ,Transmit Data ...

  4. 如何解决PHP里大量数据循环时内存耗尽的问题

    最近在开发一个PHP程序时遇到了下面的错误: PHP Fatal error: Allowed memory size of 268 435 456 bytes exhausted 错误信息显示允许的 ...

  5. Bufferread有readline()使得字符输入更加方便

    原则:保证编解码方式的统一,才能不至于出现错误. Io包的InputStreamread称为从字节流到字符流的桥转换类.这个类可以设定字符转换方式. OutputStreamred:字符到字节 Buf ...

  6. 【BZOJ】1668: [Usaco2006 Oct]Cow Pie Treasures 馅饼里的财富(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1668 裸dp.. f[i][j]表示i行j列最大能拿到 f[i][j]=max(f[i+1][j-1 ...

  7. php的form中元素name属性相同时的取值问题

    php的form中元素name属性相同时的取值问题:修改元素的名称,在名称后面加上 '[]',然后取值时即可得array()数组. 一.以复选框为例: <html> <head> ...

  8. ES插件elasticsearch-mapper-attachments 2.3.4及各个版本正确下载地址

    ES版本更新那么快,文档链接你也倒是跟上啊, 插件zip包下载,都是error link...难不成是我网络原因? 下载zip页面报错信息: This XML file does not appear ...

  9. c# http请求,获取非200时的响应体

    HttpWebResponse res = null; try { res = request.GetResponse() as HttpWebResponse; } catch (WebExcept ...

  10. 学习《深入理解C#》—— 泛型 (第三章3.1---3.2)

    泛型是什么? 泛型(generic)是C# 2.0和通用语言运行时(CLR)的一个新特性.泛型为.NET框架引入了类型参数(type parameters)的概念.类型参数使得设计类和方法时,不必确定 ...