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. POJ 3829 Seat taking up is tough(——只是题目很长的模拟)

    题目链接: http://poj.org/problem?id=3829 题意描述: 输入矩阵的大小n和m,以及来占位置的人数k 输入n*m的教室座位矩阵,每个值表示该座位的满意度 输入每个人来占位置 ...

  2. C# 小笔记

    1,Using using (var ws = new WebSocket ("ws://dragonsnest.far/Laputa")) { ws.OnMessage += ( ...

  3. 最强PostMan使用教程(1)

    最近需要测试产品中的REST API,无意中发现了PostMan这个chrome插件,把玩了一下,发现postman秉承了一贯以来google工具强大,易用的特质.独乐乐不如众乐乐,特此共享出来给大伙 ...

  4. 【编程技巧】ExtJs 设置GridPanel表格文本垂直居中

    详细讲解见 http://blog.csdn.net/li396864285/article/details/9310983 以下是我改修的代码: {         width:90,        ...

  5. C#读取固定文本格式的txt文件

    C#读取固定文本格式的txt文件 一个简单的C#读取txt文档的程序,文档中用固定的格式存放着实例数据. //判断关键字在文档中是否存在 ] == "设备ID:107157061" ...

  6. 注入理解之APC注入

    近期学习做了一个各种注入的MFC程序,把一些心得和体会每天分享一些 APC(Asynchronous procedure call)异步程序调用,在NT中,有两种类型的APCs:用户模式和内核模式.用 ...

  7. LINUX文档管理命令

    body, table{font-family: 微软雅黑} table{border-collapse: collapse; border: solid gray; border-width: 2p ...

  8. localhost或本机ip无法连接数据库问题解决与原因

    解决办法:将localhost替换为127.0.0.1 原因@参考文章:navicat在电脑没有联网的情况下,并不会把localhost解析成127.0.0.1,而mysql默认情况下只支持127.0 ...

  9. 译-BSA NSH Command介绍

    BSA NSH Command全称BMC BladeLogic Network Shell Command,是基于ZSH的shell. 1 说明 NSH命令行(全称Network  Shell,又称为 ...

  10. 一、Html简介

    html什么东西呢? hypertext markup language(超文本标记语言).超级文本标记语言是标准通用标记语言下的一个应用,也是一种规范,一种标准, 它通过标记符号来标记要显示的网页中 ...