본문 바로가기

SQL/LeetCode

[SQL] LeetCode: 627. Swap Salary

627. Swap Salary

 

문제

 

Write an SQL query 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 = IF(sex = 'f', 'm','f')
 
 
+) 다른 풀이
 
UPDATE salary
SET sex = CASE WHEN sex = 'f' THEN 'm' ELSE 'f' END