SQL数据库表中两行数据互换

2024-11-30 01:42:18
推荐回答(2个)
回答1:

做列表上下移动的时候遇到过,改造了下可以看看
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')

回答2:

想办法写个语句把表中两行ID实现交换就行了!其它的都不用动!

不过好像要实现这个得写存储过程!