Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit f39943e

Browse files
refactor 627
1 parent da14ca3 commit f39943e

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

database/_627.sql

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
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+
125
--solution 1:
226
update salary
327
set sex = CHAR(ASCII('f') ^ ASCII('m') ^ ASCII(sex));

0 commit comments

Comments
 (0)