Example:
| id | name | sex | salary |
|---|---|---|---|
| 1 | A | m | 2500 |
| 2 | B | f | 1500 |
| 3 | C | m | 5500 |
| 4 | D | f | 500 |
After running your update statement, the above salary table should have the following rows:
| id | name | sex | salary |
|---|---|---|---|
| 1 | A | f | 2500 |
| 2 | B | m | 1500 |
| 3 | C | f | 5500 |
| 4 | D | m | 500 |
使用 sql swap 表中的 sex 字段,不能用select,是能使用 update
update salary set sex = IF(sex = 'm', 'f', 'm');
update salary set sex = CHAR(ASCII('f') ^ ASCII('m') ^ ASCII(sex));
update salary set sex = (case when sex='m' then 'f' when sex='f' then 'm' end)
博客提到在运行更新语句后,工资表会有特定行,重点是使用 SQL 的 update 语句来交换表中的 sex 字段,且不能使用 select 语句。
1868

被折叠的 条评论
为什么被折叠?



