1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode/problem/swap-salary.html

52 lines
1.7 KiB
HTML
Raw Normal View History

2022-03-27 18:35:17 +08:00
<p>Table: <code>Salary</code></p>
<pre>
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| id | int |
| name | varchar |
| sex | ENUM |
| salary | int |
+-------------+----------+
2023-12-09 18:42:21 +08:00
id is the primary key (column with unique values) for this table.
The sex column is ENUM (category) value of type (&#39;m&#39;, &#39;f&#39;).
2022-03-27 18:35:17 +08:00
The table contains information about an employee.
</pre>
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p>Write a solution to swap all <code>&#39;f&#39;</code> and <code>&#39;m&#39;</code> values (i.e., change all <code>&#39;f&#39;</code> values to <code>&#39;m&#39;</code> and vice versa) with a <strong>single update statement</strong> and no intermediate temporary tables.</p>
2022-03-27 18:35:17 +08:00
<p>Note that you must write a single update statement, <strong>do not</strong> write any select statement for this problem.</p>
2023-12-09 18:42:21 +08:00
<p>The result format is in the following example.</p>
2022-03-27 18:35:17 +08:00
<p>&nbsp;</p>
2023-12-09 18:42:21 +08:00
<p><strong class="example">Example 1:</strong></p>
2022-03-27 18:35:17 +08:00
<pre>
<strong>Input:</strong>
Salary table:
+----+------+-----+--------+
| id | name | sex | salary |
+----+------+-----+--------+
| 1 | A | m | 2500 |
| 2 | B | f | 1500 |
| 3 | C | m | 5500 |
| 4 | D | f | 500 |
+----+------+-----+--------+
<strong>Output:</strong>
+----+------+-----+--------+
| id | name | sex | salary |
+----+------+-----+--------+
| 1 | A | f | 2500 |
| 2 | B | m | 1500 |
| 3 | C | f | 5500 |
| 4 | D | m | 500 |
+----+------+-----+--------+
<strong>Explanation:</strong>
(1, A) and (3, C) were changed from &#39;m&#39; to &#39;f&#39;.
(2, B) and (4, D) were changed from &#39;f&#39; to &#39;m&#39;.
</pre>