File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 11# Time: O(n)
22# Space: O(1)
33
4+ # Given a table salary, such as the one below, that has m=male and f=female values.
5+ # 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.
6+ #
7+ # For example:
8+ # | id | name | sex | salary |
9+ # |----|------|-----|--------|
10+ # | 1 | A | m | 2500 |
11+ # | 2 | B | f | 1500 |
12+ # | 3 | C | m | 5500 |
13+ # | 4 | D | f | 500 |
14+ #
15+ # After running your query, the above salary table should have the following rows:
16+ # | id | name | sex | salary |
17+ # |----|------|-----|--------|
18+ # | 1 | A | f | 2500 |
19+ # | 2 | B | m | 1500 |
20+ # | 3 | C | f | 5500 |
21+ # | 4 | D | m | 500 |
22+
423UPDATE salary SET sex = IF(sex = ' m' , ' f' , ' m' )
You can’t perform that action at this time.
0 commit comments