627. Swap Salary
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的更多相关文章
- 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 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 ...
- [SQL]LeetCode627. 交换工资 | Swap Salary
SQL架构 create table ), sex ), salary int) Truncate table salary insert into salary (id, name, sex, sa ...
- [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 ...
- 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语句,将 ...
- 2017/11/3 Leetcode 日记
2017/11/3 Leetcode 日记 654. Maximum Binary Tree Given an integer array with no duplicates. A maximum ...
- All LeetCode Questions List 题目汇总
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems clas ...
- Leetcode中的SQL题目练习(一)
595. Big Countries https://leetcode.com/problems/big-countries/description/ Description name contine ...
随机推荐
- httpclient4.5 的一些细节
本文转自:http://mercymessi.iteye.com/blog/2250161 httpclient是Apache下的一个用于执行http网络访问的一个工具包. 大致流程:新建一个http ...
- mysql学习笔记2--mysql的基本使用
4. 运行和关闭MySQL服务器 首先检查MySQL服务器正在运行与否.在资源管理器查看有没有mysqld的进程,如果MySQL正在运行,那么会看到列出来的 mysqld 进程.如果服务器没有运行,那 ...
- SpringBoot使用maven构建
1.使用maven作为parent管理 maven用户可以继承spring-boot-starter-parent项目获取合适的默认设置.该父项目提供一下特性: 默认编译级别为Java1.6 源编码格 ...
- 个别图片IE中无法显示问题
今天有人保障,某些图片在IE下无法打开,但是其他浏览器均没有问题.以前还真没遇到过这类问题,从上至下查看了一遍,能排除的因素基本都排除了,还是不知道为什么不能显示,真是奇怪了.最后注意到无法显示的图片 ...
- div随页面滚动遇顶固定的两种方法(js&jQuery)
一.遇顶固定的例子 我一直以为是某个div或层随屏幕滚动,遇顶则固定,离开浏览器顶部又还原这样的例子其实不少,其实它的名字叫“层的智能浮动效果”.目前我们在国内的商业网站上就常常看到这样的效果了.例如 ...
- EasyUI Ajax 表单
创建form <divstyle="width:230px;background:#E0ECFF;padding:10px;"> <formid=&quo ...
- 什么是Spring Cloud
Spring Cloud是一系列框架的有序集合.它利用Spring Boot的开发便利性巧妙地简化了分布式系统基础设施的开发,如服务发现注册.配置中心.消息总线.负载均衡.断路器.数据监控等,都可以用 ...
- NYOJ 1009 So Easy[Ⅰ]【简单题】
/* 题目大意:求三角形的外接圆 解题思路:c/sin(C)=2R,先求出cos,在求出sin 关键点:直接调用库 解题人:lingnichong 解题时间:2014-10-18 10:19:33 解 ...
- hdu 2528:Area(计算几何,求线段与直线交点 + 求多边形面积)
Area Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- Hadoop1.2.1 单机模式安装
首先安装JDK: 然后安装hadoop: 最后的实例测试:首先在 /opt/data 目录下创建 input目录, 然后把hadoop的conf目录下的所有xml文件拷贝到上面的input目录, 然后 ...