在MySQL中交换特定的列值
让我们首先创建一个表table-
create table DemoTable1504-> (
-> Id int,
-> FirstName varchar(20)
-> );
使用插入命令在表中插入一些记录-
insert into DemoTable1504 values(101,'Chris');insert into DemoTable1504 values(102,'Bob');
insert into DemoTable1504 values(103,'David');
insert into DemoTable1504 values(104,'Mike');
使用select语句显示表中的所有记录-
select * from DemoTable1504 ;
这将产生以下输出-
+------+-----------+| Id | FirstName |
+------+-----------+
| 101 | Chris |
| 102 | Bob |
| 103 | David |
| 104 | Mike |
+------+-----------+
4 rows in set (0.00 sec)
以下是交换特定列值的查询-
update DemoTable1504-> set FirstName='Carol'
-> where Id=103
-> and FirstName <> 'Carol';
Rows matched: 1 Changed: 1 Warnings: 0
让我们再次检查表记录-
select * from DemoTable1504;
这将产生以下输出-
+------+-----------+| Id | FirstName |
+------+-----------+
| 101 | Chris |
| 102 | Bob |
| 103 | Carol |
| 104 | Mike |
+------+-----------+
4 rows in set (0.00 sec)
以上是 在MySQL中交换特定的列值 的全部内容, 来源链接: utcz.com/z/335365.html