Coding Interview

[leetcode] 627. Swap Salary

눈가락 2025. 5. 12. 12:49

https://leetcode.com/problems/swap-salary

 

Salary Table 의 sex column 내용을 조건에 따라 업데이트한다.

case 문을 set 에서도 사용 가능하다는 것을 알 수 있다.

 

UPDATE salary 
SET sex = (
    CASE
        WHEN sex = 'f' THEN 'm'
        WHEN sex = 'm' THEN 'f'
    END
)

 


 

< English (feedback by ChatGPT) >

 

Update sex column in salary table according to a condition.

(We update the sex column in the Salary table based on certain conditions.)

We can see case statement is available in set statement.

(This shows that a CASE statement can also be used within a SET clause.)