Snoopy [리트코드/SQL] 6. Swap Salary (627)
코딩테스트/리트코드 SQL

[리트코드/SQL] 6. Swap Salary (627)

Sooyoon Jeong 2022. 12. 5.

👉https://leetcode.com/problems/swap-salary/description/?envType=study-plan&id=sql-i

 

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


🤔 문제 분석

1) 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.

2) Note that you must write a single update statement, do not write any select statement for this problem.

3) The query result format is in the following example

 

💡 풀이

UPDATE Salary
SET 
    SEX = CASE SEX
        WHEN 'm' THEN 'f'
        ELSE 'm'
    END

 

✍️ check point

일반적인 업데이트 문 사용하기

UPDATE 테이블명
SET 필드명 = 변경할 새로운 값
WHERE 조건문

조건문을 지정하지 않으면 전체에 대해 update된다.

 

JOIN

 

댓글