[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 ...
随机推荐
- LeetCode - 637. Average of Levels in Binary Tree
Given a non-empty binary tree, return the average value of the nodes on each level in the form of an ...
- C#串口介绍以及简单串口通信程序设计实现
C#串口介绍以及简单串口通信程序设计实现 周末,没事干,写个简单的串口通信工具,也算是本周末曾来过,废话不多,直接到主题 串口介绍 串行接口简称串口,也称串行通信接口或串行通讯接口(通常指COM接口) ...
- 精品绿色便携软件 & 录制操作工具
https://www.vtaskstudio.com/index.php 录制宏工具 https://soft.anruan.com/29821/ TinyTask V1.5 电脑版 https ...
- 解决VMware安装Ubuntu的过程中窗口过小无法看到按钮的问题
最近在用VMware安装Ubuntu的时候,发现竟然只能看到部分界面,鼠标拖拽也没有用,就是看不到完整的界面,那要我怎么按下一步啊~(真是哭笑不得%>_<%),或者按TAB键,靠自己的想象 ...
- sencha touch Demo(示例)(2014-6-25)
这是一个开源示例,是我对sencha touch的深层应用.已停止更新 sencha touch版本:2.2.1/2.3.1 源码地址: https://bitbucket.org/moLangZai ...
- Windows平台编译memcached 1.2.6
两个项目libevent.memcached,Platform Toolset使用Visual Studio 2013 - Windows XP (v120_xp).在编译memcached时会提示& ...
- 【CF932G】Palindrome Partition 回文自动机
[CF932G]Palindrome Partition 题意:给你一个字符串s,问你有多少种方式,可以将s分割成k个子串,设k个子串是$x_1x_2...x_k$,满足$x_1=x_k,x_2=x_ ...
- SQL已存在则更新不存在则插入
不废话,下代码. replace into T_Life_UMessage(message_id,account,isread,isdelete)values(?,?,1,1) 意思是若不存在则插入要 ...
- Spring JPA配置讲解
JPA是Java EE5规范之一,是一个orm规范,由厂商来实现该规范.目前有hibernate,OpenJPA,TopLink和EclipseJPA等实现 Spring提供三种方法集成JPA: 1. ...
- JSP学习_02
JavaBean是特殊的Java类,使用Java语言编写,遵守JavaBean规范JavaBean同其他Java类一些独一无二的属性:拥有一个默认的构造函数需要被序列化并实现Serializable接 ...