update student t set
t.name =
(case when t.id = '1'
then (select t2.name from student t2 where t2.id ='2')
else (select t2.name from student t2 where t2.id ='1')
end) where t.id in ('1','2')
为什么要交换数据,只要修改下桌号不就好了吗两个表交换数据可以考虑如下思路
前提是两表要有相似的结构
1.将想交换的两条数据分别插入目标表
2.删除源数据
参考sql语句
insert into T1(id, name, age) select id, name, age from T2 where id=1
insert into T2(id, name, age) select id, name, age from T1 where id=2
delete from T1 where id=2
delete from T2 where id=1
只是个思路,实际 *** 作可以比这个麻烦点。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)