Record1

[LeetCode] 627. Swap Salary [MySQL] UPDATE with IF statement

honey bun 2020. 12. 1. 12:30
728x90
반응형

 

leetcode.com/problems/swap-salary/

 

Swap Salary - LeetCode

Level up your coding skills and quickly land a job. This is the best place to expand your knowledge and get prepared for your next interview.

leetcode.com

Given a table salary, such as the one below, that has m=male and f=female values. 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 temp table.

Note that you must write a single update statement, DO NOT write any select statement for this problem.

 


UPDATE salary
SET sex = IF(sex='m', 'f', 'm')

UPDATE Syntax

UPDATE TABLE
SET COL1=VAL1, COL2=VAL2
WHERE CONDITION

IF Statement Syntax

IF(condition, true, false)

728x90
반응형