Skip to content

Commit 9e89551

Browse files
committedApr 25, 2020
refactor 627
1 parent 9a3f400 commit 9e89551

File tree

1 file changed

+0
-24
lines changed

1 file changed

+0
-24
lines changed
 

‎database/_627.sql

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,3 @@
1-
--627. Swap Salary
2-
--
3-
--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.
4-
--
5-
--Note that you must write a single update statement, DO NOT write any select statement for this problem.
6-
--
7-
--
8-
--Example:
9-
--
10-
--| id | name | sex | salary |
11-
--|----|------|-----|--------|
12-
--| 1 | A | m | 2500 |
13-
--| 2 | B | f | 1500 |
14-
--| 3 | C | m | 5500 |
15-
--| 4 | D | f | 500 |
16-
17-
--After running your update statement, the above salary table should have the following rows:
18-
--| id | name | sex | salary |
19-
--|----|------|-----|--------|
20-
--| 1 | A | f | 2500 |
21-
--| 2 | B | m | 1500 |
22-
--| 3 | C | f | 5500 |
23-
--| 4 | D | m | 500 |
24-
251
--solution 1:
262
update salary
273
set sex = CHAR(ASCII('f') ^ ASCII('m') ^ ASCII(sex));

0 commit comments

Comments
 (0)
Please sign in to comment.