[LeetCode] 627. Swap Salary_Easy tag: SQL
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的更多相关文章
- [LeetCode] 176. Second Highest Salary_Easy tag: SQL
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- 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] 182. Duplicate Emails_Easy tag: SQL
Write a SQL query to find all duplicate emails in a table named Person. +----+---------+ | Id | Emai ...
- [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 ...
- [LeetCode] 595. Big Countries_Easy tag: SQL
There is a table World +-----------------+------------+------------+--------------+---------------+ ...
- 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 ...
- [LeetCode] 610. Triangle Judgement_Easy tag: SQL
A pupil Tim gets homework to identify whether three line segments could possibly form a triangle. Ho ...
- [LeetCode] 607. Sales Person_Easy tag: SQL
Description Given three tables: salesperson, company, orders.Output all the names in the table sales ...
随机推荐
- JVM工具jinfo实践
一.jinfo命令格式 命令格式: jinfo [option] <pid> Usage: jinfo [option] <pid> (to connect to runnin ...
- X-Requested-With导致CSRF失败
在漫漫渗透之路中,眼前一亮的发现一个站.Referer字段没有检查,POST参数中的动态token也没有检查,这不是带一波CSRF的节奏嘛.但是遇到一个之前我没遇到的问题导致我CSRF失败,这个问题或 ...
- [转]Windows上搭建Kafka运行环境
[转]http://www.cnblogs.com/alvingofast/p/kafka_deployment_on_windows.html Windows上搭建Kafka运行环境 完整解决方 ...
- CentOS系统下docker的安装与卸载
Docker简介 Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制, ...
- CentOS 6.8下Apache绑定多个域名的方法
如何通过设置Apache的http.conf文件,进行多个域名的绑定(假设我们要绑定的域名是discuz11.com和discuz22.com,独立IP为25.25.25.25). 域名/IP地址 域 ...
- BC32206 错误
出现这种情况的话 排除代码引入dll版本的原因 看下是不是 你之前用net reflector 生成了pdb文件 导致项目引入的版本都是他生成的文件 处理方案就是 用everything 找到这个dl ...
- Memcached 简单利用和简单了解(Mac的安装和使用)
Memcached 是一种用于分布式应用的一种缓存机制.应用也比较广泛.这里来学习一下. 首先Memcached 是分布式网站架构都需要用到的缓存机制.缓存就是服务器利用多余的空间上开辟了一个储存空间 ...
- 微信都在用的移动敏捷测试方法和工具|视频+PPT
本文是腾讯优测总监雷彬在MPD2016 北京站上的演讲视频.他详细讲述了腾讯多年来在实践敏捷研发过程中测试的优化之路,为测试角色(包括测试工程师和开发自测)提供敏捷作业的思路.点击此处观看视频.时长5 ...
- MySQL 重做日志文件
一.innodb log的基础知识 · innodb log顾名思义:即innodb存储引擎产生的日志,也可以称为重做日志文件,默认在innodb_data_home_dir下面有两个文件ib_log ...
- linux:正则表达式grep命令
基本语法一个正则表达式通常被称为一个模式(pattern),为用来描述或者匹配一系列符合某个句法规则的字符串. 一.选择:| | 竖直分隔符表示选择,例如"boy|girl"可 ...