LeetCode 627. exchange wages (MySQL)

Title
given a salary table, as shown below, there are m = f = male and female values. F and m are all exchange value (e.g., change the value of m f all, and vice versa). It requires only one update (the Update) statement, and no intermediate temporary table.
Note that you will only write an Update statement, please do not write any Select statement.
E.g:

id name sex salary
1 A m 2500
2 B f 1500
3 C m 5500
4 D f 500

After running the update statements you have written, you will get the following table:

id name sex salary
1 A f 2500
2 B m 1500
3 C f 5500
4 D m 500

Source: stay button (LeetCode)
link: https: //leetcode-cn.com/problems/swap-salary

知识点:
1、UPDATE语句:UPDATE table_name SET column_name=nae_value[, column_name=new_value] WHERE column_name=some_value
2、CASE WHEN THEN … ELSE END

UPDATE salary
SET sex=(CASE WHEN sex='m' THEN 'f' ELSE 'm' END);
Released eight original articles · won praise 0 · Views 104

Guess you like

Origin blog.csdn.net/weixin_43346653/article/details/104344482