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 |

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的更多相关文章

  1. [LeetCode] 176. Second Highest Salary_Easy tag: SQL

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

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

  3. [LeetCode] 182. Duplicate Emails_Easy tag: SQL

    Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...

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

  5. [LeetCode] 595. Big Countries_Easy tag: SQL

    There is a table World +-----------------+------------+------------+--------------+---------------+ ...

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

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

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

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

  8. [LeetCode] 610. Triangle Judgement_Easy tag: SQL

    A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. Ho ...

  9. [LeetCode] 607. Sales Person_Easy tag: SQL

    Description Given three tables: salesperson, company, orders.Output all the names in the table sales ...

随机推荐

  1. xmapp 404设置

    这样做的好处一个是很友好,另一个是对于你的网站会更安全些,如果没设置,别人在你的网址后随便输入一个路径,会显示404错误,并且会显示你的服务器版本号,服务器配置一目了然,为了避免这种情况,可以设置错误 ...

  2. C语言工具:LCC-Win32+v3.0

    LCC-Win32+v3.0(带汉化).rar  小巧精悍的工具 安装步骤: 1.先安装 LCC-Win32V3.0.exe 假如安装目录为:C:\lcc 2.再安装 LCC-Win32V3.0汉化补 ...

  3. sencha touch 自定义事件

    需要添加自定义事件可以如下: this.fireEvent('back', this); 此方法第一个参数为你想要监听的事件,之后的参数为你想要传递的参数一般来说第一个参数最好是控件本身. 同理这个方 ...

  4. jvisualvm连接远程应用终于成功,附踩大坑记录!!(一:jstatd方式)

    一.问题概述 连接远程java应用除了jstatd方式,还有jmx方式.不必拘泥于一种,一种不行可以果断尝试另一种,兴许就行了. 姊妹篇在这: jvisualvm连接远程应用终于成功,附踩大坑记录!! ...

  5. Sublime text3配置LiveReload 浏览器即时刷新

    1.在sublime控件台 install livereload插件(缺点:每次重新打开Sublime都需要启动) 2.配置Preference > Package Settings > ...

  6. C++的函数重载和main函数之外的工作

    今天被问到一个C++的函数重载问题,一下子没反应过来,这种基础的问题竟然忘记了,以下记录一下这些忘记的内容.     函数重载 函数重载的定义是:在相同的作用域中,如果函数具有相同名字而仅仅是形参表不 ...

  7. iOS开发中id、NSObject *、id、instancetype四者有什么区别?

      在使用Objective-C语言进行iOS应用开发的时候,常常会涉及到id.NSObject *.id.instancetype这四个概念的使用,但这四者也是iOS初学者最易混淆的内容,下面小编看 ...

  8. Html5游戏框架createJs组件--EaselJS(二)绘图类graphics

    有端友问我是否有文档,有确实有,但没有中文的,只有英文的,先提供浏览地址供大家参考学习createJs英文文档.                        EaselJS其实主要就是createJ ...

  9. python---不支持中文注释解决办法

    很神奇的一件事儿,pycharm不支持中文注释,具体解决办法: #-*- coding: utf- -*- 具体使用:

  10. postgresql----网络地址类型和函数

    本人对网络这块实在是搞不清楚,要是能有人推荐一下资料就好了!不知道有没有跟我一样呢?!所以在这里先贴一点从其他地方搞来的一些IPv4的东东. IPv4主要包括一下5类地址 A类: 0 7位 网络号 2 ...