mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	add leetcode problem-cn part3
This commit is contained in:
		
							
								
								
									
										51
									
								
								算法题(国内版)/problem (English)/变更性别(English) [swap-salary].html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								算法题(国内版)/problem (English)/变更性别(English) [swap-salary].html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,51 @@
 | 
			
		||||
<p>Table: <code>Salary</code></p>
 | 
			
		||||
 | 
			
		||||
<pre>
 | 
			
		||||
+-------------+----------+
 | 
			
		||||
| Column Name | Type     |
 | 
			
		||||
+-------------+----------+
 | 
			
		||||
| id          | int      |
 | 
			
		||||
| name        | varchar  |
 | 
			
		||||
| sex         | ENUM     |
 | 
			
		||||
| salary      | int      |
 | 
			
		||||
+-------------+----------+
 | 
			
		||||
id is the primary key for this table.
 | 
			
		||||
The sex column is ENUM value of type ('m', 'f').
 | 
			
		||||
The table contains information about an employee.
 | 
			
		||||
</pre>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
 | 
			
		||||
<p>Write an SQL query to swap all <code>'f'</code> and <code>'m'</code> values (i.e., change all <code>'f'</code> values to <code>'m'</code> and vice versa) with a <strong>single update statement</strong> and no intermediate temporary tables.</p>
 | 
			
		||||
 | 
			
		||||
<p>Note that you must write a single update statement, <strong>do not</strong> write any select statement for this problem.</p>
 | 
			
		||||
 | 
			
		||||
<p>The query result format is in the following example.</p>
 | 
			
		||||
 | 
			
		||||
<p> </p>
 | 
			
		||||
<p><strong>Example 1:</strong></p>
 | 
			
		||||
 | 
			
		||||
<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 'm' to 'f'.
 | 
			
		||||
(2, B) and (4, D) were changed from 'f' to 'm'.
 | 
			
		||||
</pre>
 | 
			
		||||
		Reference in New Issue
	
	Block a user