Skip to content

Commit

Permalink
Update 0627.(Easy) Swap Salary.sql
Browse files Browse the repository at this point in the history
  • Loading branch information
haibarawu authored Jun 4, 2020
1 parent 6876c6b commit 364823e
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Database/0627.(Easy) Swap Salary.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
/****************************************************************************************************
627. Swap Salary
627. 交换工资
Difficulty: Easy
https://leetcode.com/problems/swap-salary/
https://leetcode.com/articles/swap-salary/
SQL Schema:
create table if not exists salary(id int, name varchar(100), sex char(1), salary int)
Truncate table salary
insert into salary (id, name, sex, salary) values ('1', 'A', 'm', '2500')
insert into salary (id, name, sex, salary) values ('2', 'B', 'f', '1500')
insert into salary (id, name, sex, salary) values ('3', 'C', 'm', '5500')
insert into salary (id, name, sex, salary) values ('4', 'D', 'f', '500')
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 statement and no intermediate temp table.
Note that you must write a single update statement, DO NOT write any select statement for this problem.
给定一个 salary 表,如下所示,有 m = 男性 和 f = 女性 的值。
交换所有的 f 和 m 值(例如,将所有 f 值更改为 m,反之亦然)。要求只使用一个更新(Update)语句,并且没有中间的临时表。
注意,您必只能写一个 Update 语句,请不要编写任何 Select 语句。
Example:
| id | name | sex | salary |
Expand All @@ -34,6 +46,9 @@ UPDATE salary
SET sex = IIF(sex = 'm', 'f', 'm')


/****************************************************************************************************/


--Method2:
UPDATE salary
SET sex =
Expand Down

0 comments on commit 364823e

Please sign in to comment.