sql 两列数据交换

MSSQL的处理方法

 
update table1
set field_1 = field_2, field_2 = field_1
可是MySQL就不能这样写,不然一列会覆盖另一列记录
 
MySQL语句如下
update table1 a, table1 b
set a.field_1 = b.field_2, a.field_2 = b.field_1
where a.id = b.id
 
 
 
转载:http://blog.163.com/lz_lls/blog/static/9793480320123273362400/
posted @ 2015-05-07 11:16  水飝飞天  阅读(1026)  评论(0编辑  收藏  举报