-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path627. Swap Salary.sql
More file actions
30 lines (24 loc) · 867 Bytes
/
627. Swap Salary.sql
File metadata and controls
30 lines (24 loc) · 867 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
Question 627. Swap Salary
Link: https://leetcode.com/problems/swap-salary/description/
Table: Salary
+-------------+----------+
| Column Name | Type |
+-------------+----------+
| id | int |
| name | varchar |
| sex | ENUM |
| salary | int |
+-------------+----------+
id is the primary key (column with unique values) for this table.
The sex column is ENUM (category) value of type ('m', 'f').
The table contains information about an employee.
Write a solution to 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 temporary tables.
Note that you must write a single update statement, do not write any select statement for this problem.
*/
UPDATE Salary
SET sex = (CASE
WHEN sex = 'm'
THEN 'f'
ELSE 'm'
END)